php防sql注入代码
一款比较完美的php防sql注入代码,很多初学者都有被sql注入的经验吧,今天我们来分享你一款比较完整的sql防注入代码,有需要的同学可以参考一下.
php防sql注入代码如下:
- <?php
-
-
-
-
-
-
-
-
- $ArrFiltrate=array("'","or","and","union","where");
-
- $StrGoUrl="";
-
- function FunStringExist($StrFiltrate,$ArrFiltrate){
- foreach ($ArrFiltrate as $key=>$value){
- if (eregi($value,$StrFiltrate)){
- return true;
- }
- }
- return false;
- }
-
- if(function_exists(array_merge)){
- $ArrPostAndGet=array_merge($HTTP_POST_VARS,$HTTP_GET_VARS);
- }else{
- foreach($HTTP_POST_VARS as $key=>$value){
- $ArrPostAndGet[]=$value;
- }
- foreach($HTTP_GET_VARS as $key=>$value){
- $ArrPostAndGet[]=$value;
- }
- }
-
- foreach($ArrPostAndGet as $key=>$value){
- if (FunStringExist($value,$ArrFiltrate)){
- echo "<script language='javascript'>alert('传递的信息中不得包含{',or,and,union}等非法字符请您把他们换成{‘,OR,AND,UNION}');</script>";
- if (emptyempty($StrGoUrl)){
- echo "<script language='javascript'>history.go(-1);</script>";
- }else{
- echo "<script language='javascript'>window.location='".$StrGoUrl."';</script>";
- }
- exit;
- }
- }
-
- ?>