原生php防注入
<?php
$dbhost = "127.0.0.1";
$dbuser = "shouquan";
$dbpassword = "SF4HGkJABZpJYL6W";
$dbname = "shouquan";
//创建对象
$db = new mysqli($dbhost, $dbuser, $dbpassword, $dbname);
//判断连接是否成功
if ($db -> connect_errno <> 0) {
echo "数据库连接失败";
}else{
#
}
//弹出提示框病跳转到页面
function alert($wenzi,$url)
{
echo '<script>window.alert("'.$wenzi.'");location.href="'.$url.'";</script>';
}
//防止sql注入
function zhuru($str)
{
if (empty($str)) return false;
$str = htmlspecialchars($str);
$str = str_replace( '/', "", $str);
$str = str_replace( '"', "", $str);
$str = str_replace( '(', "", $str);
$str = str_replace( ')', "", $str);
$str = str_replace( 'CR', "", $str);
$str = str_replace( 'ASCII', "", $str);
$str = str_replace( 'ASCII 0x0d', "", $str);
$str = str_replace( 'LF', "", $str);
$str = str_replace( 'ASCII 0x0a', "", $str);
$str = str_replace( ',', "", $str);
$str = str_replace( '%', "", $str);
$str = str_replace( ';', "", $str);
$str = str_replace( 'eval', "", $str);
$str = str_replace( 'open', "", $str);
$str = str_replace( 'sysopen', "", $str);
$str = str_replace( 'system', "", $str);
$str = str_replace( '$', "", $str);
$str = str_replace( "'", "", $str);
$str = str_replace( "'", "", $str);
$str = str_replace( 'ASCII 0x08', "", $str);
$str = str_replace( '"', "", $str);
$str = str_replace( '"', "", $str);
$str = str_replace("", "", $str);
$str = str_replace(">", "", $str);
$str = str_replace("<", "", $str);
$str = str_replace("<SCRIPT>", "", $str);
$str = str_replace("</SCRIPT>", "", $str);
$str = str_replace("<script>", "", $str);
$str = str_replace("</script>", "", $str);
$str = str_replace("select","",$str);
$str = str_replace("join","",$str);
$str = str_replace("union","",$str);
$str = str_replace("where","",$str);
$str = str_replace("insert","",$str);
$str = str_replace("delete","",$str);
$str = str_replace("update","",$str);
$str = str_replace("like","",$str);
$str = str_replace("drop","",$str);
$str = str_replace("DROP","",$str);
$str = str_replace("create","",$str);
$str = str_replace("modify","",$str);
$str = str_replace("rename","",$str);
$str = str_replace("alter","",$str);
$str = str_replace("cas","",$str);
$str = str_replace("&","",$str);
$str = str_replace(">","",$str);
$str = str_replace("<","",$str);
$str = str_replace(" ",chr(32),$str);
$str = str_replace(" ",chr(9),$str);
$str = str_replace(" ",chr(9),$str);
$str = str_replace("&",chr(34),$str);
$str = str_replace("'",chr(39),$str);
$str = str_replace("<br />",chr(13),$str);
$str = str_replace("''","'",$str);
$str = str_replace("css","'",$str);
$str = str_replace("CSS","'",$str);
$str = str_replace("<!--","",$str);
$str = str_replace("convert","",$str);
$str = str_replace("md5","",$str);
$str = str_replace("passwd","",$str);
$str = str_replace("password","",$str);
$str = str_replace("../","",$str);
$str = str_replace("./","",$str);
$str = str_replace("Array","",$str);
$str = str_replace("or 1='1'","",$str);
$str = str_replace(";set|set&set;","",$str);
$str = str_replace("`set|set&set`","",$str);
$str = str_replace("--","",$str);
$str = str_replace("OR","",$str);
$str = str_replace('"',"",$str);
$str = str_replace("*","",$str);
$str = str_replace("-","",$str);
$str = str_replace("+","",$str);
$str = str_replace("/","",$str);
$str = str_replace("=","",$str);
$str = str_replace("'/","",$str);
$str = str_replace("-- ","",$str);
$str = str_replace(" -- ","",$str);
$str = str_replace(" --","",$str);
$str = str_replace("(","",$str);
$str = str_replace(")","",$str);
$str = str_replace("{","",$str);
$str = str_replace("}","",$str);
$str = str_replace("-1","",$str);
$str = str_replace(".","",$str);
$str = str_replace("response","",$str);
$str = str_replace("write","",$str);
$str = str_replace("|","",$str);
$str = str_replace("`","",$str);
$str = str_replace(";","",$str);
$str = str_replace("etc","",$str);
$str = str_replace("root","",$str);
$str = str_replace("//","",$str);
$str = str_replace("!=","",$str);
$str = str_replace("$","",$str);
$str = str_replace("&","",$str);
$str = str_replace("&&","",$str);
$str = str_replace("==","",$str);
$str = str_replace("#","",$str);
$str = str_replace("@","",$str);
$str = str_replace("mailto:","",$str);
$str = str_replace("CHAR","",$str);
$str = str_replace("char","",$str);
return $str;
}
//连接成功后,在sql写入
error_reporting(0);
?>
最近访问时间:2024-10-09 09:32:11