php 防sql注入过滤代码

高洛峰
高洛峰 原创
2016-11-29 15:10:48 1628浏览

我们提供了三个函数不来过滤一些特殊的字符,主要是利用php把sql敏感字符串给过滤掉了,好了下面来看看这款代码吧,有需要的朋友拿去看看,实例代码如下:

function phpsql_show($str){

$str = stripslashes($str);

$str = str_replace("\", "", $str);

$str = str_replace("/", "/", $str);

$str = str_replace(" ", " ", $str);

$str = str_replace(",", ",", $str);

return $str;

}

function phpsql_post($str){

$str = stripslashes($str);

$str = str_replace("|", "|", $str);

$str = str_replace("<", "&#60;", $str);

$str = str_replace(">", "&#62;", $str);

$str = str_replace("&nbsp;", "&#32;", $str);

$str = str_replace(" ", "&#32;", $str);

$str = str_replace("(", "&#40;", $str);

$str = str_replace(")", "&#41;", $str);

$str = str_replace("`", "&#96;", $str);

//$str = str_replace("'", "&#39;", $str);

$str = str_replace('"', "&#34;", $str);

$str = str_replace(",", "&#44;", $str);

$str = str_replace("$", "&#36;", $str);

$str = str_replace("", "&#92;", $str);

$str = str_replace("/", "&#47;", $str);

return $str;

}//开源代码phpfensi.com

function phpsql_replace($str){

$str = stripslashes($str);

$str = str_replace("'", "&#39;", $str);

return $str;

}


声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。