好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

php防注入代码 - php函数

php防注入代码

关于sql注入是在程序开发中基本的网站安全知识,下面我们讲了php和sql两个防注入的办法,有需要的朋友可以参考一下或自己也可以在这基础上改进,代码如下:

<?php   $magic_quotes_gpc  = get_magic_quotes_gpc();   @extract(daddslashes( $_COOKIE ));   @extract(daddslashes( $_POST ));   @extract(daddslashes( $_GET ));   if (! $magic_quotes_gpc ) {   $_FILES  = daddslashes( $_FILES );   }    function  daddslashes( $string ,  $force  = 0) {   if (! $GLOBALS [ 'magic_quotes_gpc' ] ||  $force ) {   if ( is_array ( $string )) {   foreach ( $string   as   $key  =>  $val ) {   $string [ $key ] = daddslashes( $val ,  $force );   }   }  else  {   $string  =  addslashes ( $string );   }   }   return   $string ;   }   ?> 

防注入二,代码如下:

function  inject_check($sql_str) {  //防止注入     $check = eregi( 'select|insert|update|delete|' | /*|*||./|union|into|load_file|outfile', $sql_str);     if ($check) {      echo "输入非法注入内容!";      exit ();     } else {      return $sql_str;     }    }    function checkurl() { //检查来路     if (preg_replace("/https?://([^:/]+).*/ i",  "\1" , $_SERVER[ 'HTTP_REFERER' ]) !== preg_replace( "/([^:]+).*/" ,  "\1" , $_SERVER[ 'HTTP_HOST' ])) {     header( "Location: http://HdhCmsTestphpfensi测试数据" );     exit();    }   }

查看更多关于php防注入代码 - php函数的详细内容...

  阅读:44次