当前位置:首页 > PHP教程 > php应用 > 列表

php sql通用防注入系统

发布:smiling 来源: PHP粉丝网  添加日期:2014-08-25 10:52:03 浏览: 评论:0 

本文章提供这款防sql注入代码是一款php sql双过滤非法字符的函数,他可以根据用户自定的防sql注入,先是过滤一些sql命令,再是就是把post get 过滤一次,最好验证.

php防注入代码如下:

  1. $arrfiltrate=array("update","delete","selert","drop","exec","cast","'","union"); 
  2. //出错后要跳转的url,不填则默认前一页 
  3. $strgourl=""; 
  4. //是否存在数组中的值 
  5. function funstringexist($strfiltrate,$arrfiltrate){ 
  6.     foreach ($arrfiltrate as $key=>$value){ 
  7.         if (eregi($value,$strfiltrate)){ 
  8.             return true; 
  9.         } 
  10.     } 
  11. return false; 
  12. } 
  13. //合并$_post 和 $_get 
  14. if(function_exists(array_merge)){ 
  15.     $arrpostandget=array_merge($http_post_vars,$http_get_vars); 
  16. }else{ 
  17.     foreach($http_post_vars as $key=>$value){ 
  18.         $arrpostandget[]=$value; 
  19.     } 
  20.     foreach($http_get_vars as $key=>$value){ 
  21.     $arrpostandget[]=$value; 
  22.     }//开源代码phpfensi.com 
  23. } 
  24. //验证开始 
  25. foreach($arrpostandget as $key=>$value){ 
  26.     if (funstringexist($value,$arrfiltrate)){ 
  27.         echo " "; 
  28.         if (emptyempty($strgourl)){ 
  29.             echo " "; 
  30.         }else{ 
  31.             echo " "; 
  32.         } 
  33.         echo "<script>alert('系统检测到非法字符!');history.back();</script>"; 
  34.         exit(); 
  35.     } 
  36. } 

Tags: php sql防注入

分享到: