PHP程序防止ddos,dns,集群服务器攻击
[代码] ddos,dns,集群服务器攻击QQ33258影子可以测试满意担保
006 |
$ip =$_SERVER[ 'REMOTE_ADDR' ]; |
008 |
$fileht= ".htaccess2" ; |
010 |
if (!file_exists($fileht))file_put_contents($fileht, "" ); |
012 |
$filehtarr=@ file ($fileht); |
014 |
if (in_array($ip. "\r\n" ,$filehtarr))die( "Warning:" . "<br>" . "Your IP address are forbided by some reason, IF you have any question Pls emill to shop@mydalle.com!" ); |
022 |
$fileforbid= "log/forbidchk.dat" ; |
024 |
if (file_exists($fileforbid)) |
026 |
{ if ($ time -filemtime($fileforbid)>60)unlink($fileforbid); |
030 |
$fileforbidarr=@ file ($fileforbid); |
032 |
if ($ip==substr($fileforbidarr[0],0,strlen($ip))) |
036 |
if ($ time -substr($fileforbidarr[1],0,strlen($ time ))>600)unlink($fileforbid); |
038 |
elseif($fileforbidarr[2]>600){file_put_contents($fileht,$ip. "\r\n" ,FILE_APPEND);unlink($fileforbid);} |
040 |
else {$fileforbidarr[2]++;file_put_contents($fileforbid,$fileforbidarr);} |
052 |
$ file = "log/ipdate.dat" ; |
054 |
if (!file_exists( "log" )&&!is_dir( "log" )) mkdir ( "log" ,0777); |
056 |
if (!file_exists($ file ))file_put_contents($ file , "" ); |
058 |
$allowTime = 120;//防刷新时间 |
062 |
$uri=$_SERVER[ 'REQUEST_URI' ]; |
070 |
$ipdate=@ file ($ file ); |
072 |
foreach($ipdate as $k=>$ v ) |
074 |
{ $iptem=substr($ v ,0,32); |
076 |
$uritem=substr($ v ,32,32); |
078 |
$timetem=substr($ v ,64,10); |
080 |
$numtem=substr($ v ,74); |
082 |
if ($ time -$timetem<$allowTime){ |
084 |
if ($iptem!=$checkip)$str.=$ v ; |
090 |
if ($uritem!=$checkuri)$str.=$iptem.$checkuri.$ time . "1\r\n" ; |
092 |
elseif($numtem<$allowNum)$str.=$iptem.$uritem.$timetem.($numtem+1). "\r\n" ; |
098 |
if (!file_exists($fileforbid)){$addforbidarr=array($ip. "\r\n" , time (). "\r\n" ,1);file_put_contents($fileforbid,$addforbidarr);} |
100 |
file_put_contents( "log/forbided_ip.log" ,$ip. "--" . date ( "Y-m-d H:i:s" , time ()). "--" .$uri. "\r\n" ,FILE_APPEND); |
102 |
$timepass=$timetem+$allowTime-$ time ; |
104 |
die( "Warning:" . "<br>" . "Sorry,you are forbided by refreshing frequently too much, Pls wait for " .$timepass. " seconds to continue!" ); |
114 |
if ($yesno) $str.=$checkip.$checkuri.$ time . "1\r\n" ; |
116 |
file_put_contents($ file ,$str); |
原文地址:https://www.cnblogs.com/xingmeng/p/2890303.html