html如何防止sql注入

1292
2021/1/6 12:22:55
栏目: 云计算
开发者测试专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

html如何防止sql注入

html防止sql注入的方法:

1.批量过滤post、get敏感数据,例如:

$_GET = stripslashes_array($_GET);

$_POST = stripslashes_array($_POST);

2.使用数据过滤函数,例如:

function stripslashes_array(&$array) {

while(list($key,$var) = each($array)) {

if ($key != "argc" && $key != "argv" && (strtoupper($key) != $key || "".intval($key) == "$key")) {

if (is_string($var)) {

$array[$key] = stripslashes($var);

}

if (is_array($var)) {

$array[$key] = stripslashes_array($var);

}

}

}

return $array;

}

3.替换HTML尾标签,为过滤服务,例如:

function lib_replace_end_tag($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("", "", $str);

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

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

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

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

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

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

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

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

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

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

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

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

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

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

$str=str_replace("cas","cast",$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("

",chr(13),$str);

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

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

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

return $str;

}

辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

推荐阅读: html滚动条支持触摸滑动吗