
添加時(shí)間:2019-03-06 23:49:11 編輯:成都網(wǎng)站建設(shè) 文章內(nèi)容: 1714個(gè)字 閱讀時(shí)間:約5分鐘
優(yōu)化千萬(wàn)條,安全第一條!防護(hù)不到位,站長(zhǎng)兩行淚!

<?php//2019PHP通用SQL過(guò)濾方法//啄木鳥(niǎo)建站//可以屏蔽常規(guī)的sql漏洞或注入//該程序只寫的get post過(guò)濾 其它類型可以自行添加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);}?>