1<?PHP2 //Query prohibit IP3 $ip=$_server[' REMOTE_ADDR '];4 $fileht= ". Htaccess2";5 if(!file_exists($fileht))file_put_contents($fileht,"");6 $filehtarr[Email protected]file($fileht);7 if(In_array($ip." \ r \ n ",$filehtarr)) die("Warning:". ") <br> "." Your IP address is forbided by some reason and IF you had any question Pls emill to [email protected]!]);8 9 //Add Forbidden IPTen $time= Time(); One $fileforbid= "Log/forbidchk.dat"; A if(file_exists($fileforbid)) -{if($time-Filemtime($fileforbid) >60)unlink($fileforbid); - Else{ the $fileforbidarr[Email protected]file($fileforbid); - if($ip==substr($fileforbidarr[0],0,strlen($ip))) - { - if($time-substr($fileforbidarr[1],0,strlen($time)) >600)unlink($fileforbid); + ElseIf($fileforbidarr[2]>600) {file_put_contents($fileht,$ip." \ r \ n ", file_append);unlink($fileforbid);} - Else{$fileforbidarr[2]++;file_put_contents($fileforbid,$fileforbidarr);} + } A } at } - //Anti-Refresh - $str=""; - $file= "Log/ipdate.dat"; - if(!file_exists("Log") &&!Is_dir("Log"))mkdir("Log", 0777); - if(!file_exists($file))file_put_contents($file,""); in $allowTime= 120;//anti-refresh time - $allowNum= 10;//anti-refresh times to $uri=$_server[' Request_uri ']; + $checkip=MD5($ip); - $checkuri=MD5($uri); the $yesno=true; * $ipdate[Email protected]file($file); $ foreach($ipdate as $k=$v)Panax Notoginseng{$iptem=substr($v, 0,32); - $uritem=substr($v, 32,32); the $timetem=substr($v, 64,10); + $numtem=substr($v, 74); A if($time-$timetem<$allowTime){ the if($iptem!=$checkip)$str.=$v; + Else{ - $yesno=false; $ if($uritem!=$checkuri)$str.=$iptem.$checkuri.$time." 1\r\n "; $ ElseIf($numtem<$allowNum)$str.=$iptem.$uritem.$timetem. ($numtem+1). " \ r \ n "; - Else - { the if(!file_exists($fileforbid)){$addforbidarr=Array($ip." \ r \ n ", Time()." \ r \ n ", 1);file_put_contents($fileforbid,$addforbidarr);} - file_put_contents("Log/forbided_ip.log",$ip." --".Date("Y-m-d h:i:s", Time())." --".$uri." \ r \ n ",file_append);Wuyi $timepass=$timetem+$allowTime-$time; the die("Warning:". ") <br> "." Sorry,you is forbided by refreshing frequently too much, Pls wait for ".$timepass. "Seconds to continue!"); - } Wu } - } About } $ if($yesno)$str.=$checkip.$checkuri.$time." 1\r\n "; - file_put_contents($file,$str); -?>
php--preventing DDoS Attack code