添加时间:2019-03-06 23:49:11 编辑:成都网站建设 文章内容: 1714个字 阅读时间:约5分钟
<?php//2019PHP通用SQL过滤方法//啄木鸟建站//可以屏蔽常规的sql漏洞或注入//该程序只写的get post过滤 其它类型可以自行添加function html404(){ header("http//1.1 404 not found"); header("status: 404 not found"); $htm='<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html><head> <title>404 Not Found</title> </head><body> <h1>404 Not Found</h1> <p>The requested URL was not found on this server.</p> </body></html>'; exit($htm);}function checkstr($str){ $nosql='eval|select|$_|fputs|vars[|delete|upfile|/think|function=|invokefunction|call_user_func_array'; $arr=explode('|',$nosql); foreach ($arr as $ky) { if (str_replace($ky,'##',$str)!=$str) { html404(); } }}function checksql($arr){ foreach ($arr as $key => $row) { if (is_array($row)) { checksql($row); } else { checkstr($row); } }}$url=$_SERVER['REQUEST_URI'];$url=strtolower($url);if ($url!=str_replace('index.php','',$url) || $url!=str_replace('api.php','',$url)){ html404();}checkstr($url);$post=$_POST;$get=$_GET;if ($post){ checksql($post);}if ($get){ checksql($get);}?>