• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

浅析PHP程序防止ddos,dns,集群服务器攻击的解决办法_php技巧

php 搞代码 3年前 (2022-01-26) 37次浏览 已收录 0个评论

废话不多说,上代码

<?php<BR><STRONG>//查询禁止IP<BR></STRONG>$ip =$_SERVER['REMOTE_ADDR'];<BR>$fileht=".htaccess2";<BR>if(!file_exists($fileht))<BR> file_put_contents($fileht,"");<BR>$filehtarr=@file($fileht);<BR>if(in_array($ip."\r\n",$filehtarr))<BR> die("Warning:"."<br>"."Your IP address are forbided by some reason, IF you have any question Pls emill to [email protected]!");<BR><STRONG>//加入禁止IP<BR></STRONG>$time=time();<BR>$fileforbid="log/forbidchk.dat";<BR>if(file_exists($fileforbid)) { <BR> if($time-filemtime($fileforbid)>60)<BR>  unlink($fileforbid);<BR> else {<BR>  $fileforbidarr=@file($fileforbid);<BR>  if($ip==substr($fileforbidarr[0],0,strlen($ip))) {<BR>   if($time-substr($fileforbidarr[1],0,strlen($time))>600)<BR>    unlink($fileforbid);<BR>   elseif($fileforbidarr[2]>600) {<BR>    file_put_contents($fileht,$ip."\r\n",FILE_APPEND);<BR>    unlink($fileforbid);<BR>   } else { <BR>    $fileforbidarr[2]++;<BR>    file_put_contents($fileforbid,$fileforbidarr);<BR>   }<BR>  }<BR> }<BR>}<BR><STRONG>//防刷新<BR></STRONG>$str="";<BR>$file="log/ipdate.dat";<BR>if(!file_exists("log")&&!is_dir("log"))<BR> mkdir("log",0777);<BR>if(!file_exists($file))<BR> file_put_contents($file,"");<BR>$allowTime = 120;//防刷新时间<BR>$allowNum=10;//防刷新次数<BR>$uri=$_SERVER['REQUEST_URI'];<BR>$checkip=md5($ip);<BR>$checkuri=md5($uri);<BR>$yesno=true;<BR>$ipdate=@file($file);<BR>foreach($ipdate as $k=>$v) { <BR> $iptem=substr($v,0,32);<BR> $uritem=substr($v,32,32);<BR> $timetem=substr($v,64,10);<BR> $numtem=substr($v,74);<BR> if($time-$timetem<$allowTime) {<BR>  if($iptem!=$checkip)<BR>   $str.=$v;<BR>  else {<BR>   $yesno=false;<BR>   if($uritem!=$checkuri) <BR>    $str.=$iptem.$checkuri.$time."1\r\n";<BR>   elseif($numtem<$allowNum)<BR>    $str.=$iptem.$uritem.$timetem.($numtem+1)."\r\n";<BR>   else {<BR>    if(!file_exists($fileforbid)) {<BR>     $addforbidarr=array($ip."\r\n",time()."\r\n",1);<BR>     file_put_contents($fileforbid,$addforbidarr);<BR>    }<BR>    file_put_contents("log/forbided_ip.log",$ip."--".date("Y-m-d H:i:s",ti<p style="color:transparent">。本文来源gao!%daima.com搞$代*!码网1</p><cite>搞代gaodaima码</cite>me())."--".$uri."\r\n",FILE_APPEND);<BR>    $timepass=$timetem+$allowTime-$time;<BR>    die("Warning:"."<br>"."Sorry,you are forbided by refreshing frequently too much, Pls wait for ".$timepass." seconds to continue!");<BR>   }<BR>  }<BR> }<BR>}<BR>if($yesno) $str.=$checkip.$checkuri.$time."1\r\n";<BR>file_put_contents($file,$str);<BR>?><BR>

搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:浅析PHP程序防止ddos,dns,集群服务器攻击的解决办法_php技巧
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址