Home  >  Article  >  php教程  >  sql 注入 字符的检测函数

sql 注入 字符的检测函数

WBOY
WBOYOriginal
2016-06-13 10:11:58968browse

自己写的一款sql注入检测函数,可以有效的检测用户post,get过来的参考进行过滤,有需要的朋友参考一下。

 代码如下 复制代码

/*sql 注入 字符的检测
* 在所有用户输入的数据,post传参, get传参 都需要检测下 
* 如果有匹配到关键字 则 返回该关键字  否则返回false
* 这个和敏感字符的检测不是一样的
*/
function Filter_SQL($strData)
{
 $strFilter=$blnFlag=$arrayFilter='';

 $strFilter="'|and|(|)|exec|insert|select|delete|update|count|*|%27|chr|mid|master|truncate|char|declare|union|or"; //需要过滤的字符,可以自己添,"|"是分隔符
 $blnFlag=false;   //过滤标志,如果产生过滤,那么就是真
 
 $arr=explode("|",$strFilter); 
 $str="";
 
 foreach($arr as $row)
 {
  $str.=preg_quote($row)."|";
 } 
 
 $str=trim($str,"|"); 
 
 if(preg_match('/'.$str.'/i',$strData,$word))
 {
  return $word[0];
 }
 
 return false;
}

/*
测试
$string="fasdf union ";
echo Filter_SQL($string);
*/

?>

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn