首页 > 开发 > PHP > 正文

php sql通用防注入系统

2024-05-04 21:58:53
字体:
来源:转载
供稿:网友

本文章提供这款防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. //合并$_post 和 $_get 
  13. if(function_exists(array_merge)){ 
  14.     $arrpostandget=array_merge($http_post_vars,$http_get_vars); 
  15. }else
  16.     foreach($http_post_vars as $key=>$value){ 
  17.         $arrpostandget[]=$value
  18.     } 
  19.     foreach($http_get_vars as $key=>$value){ 
  20.     $arrpostandget[]=$value
  21.     }//开源代码Vevb.com 
  22. //验证开始 
  23. foreach($arrpostandget as $key=>$value){ 
  24.     if (funstringexist($value,$arrfiltrate)){ 
  25.         echo " "
  26.         if (emptyempty($strgourl)){ 
  27.             echo " "
  28.         }else
  29.             echo " "
  30.         } 
  31.         echo "<script>alert('系统检测到非法字符!');history.back();</script>"
  32.         exit(); 
  33.     } 

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表