日期:2010-11-25 08:16:00 来源:本站整理
php网站被攻击避免办法[网站编程]
本文“php网站被攻击避免办法[网站编程]”是由七道奇为您精心收集,来源于网络转载,文章版权归文章作者所有,本站不对其观点以及内容做任何评价,请读者自行判断,以下是其具体内容:
近来网站常常被攻击,后来想到了一个操纵php教程来避免网站受攻击的办法,下面是我的代码,代码不是最好的,按照自己的需求来做,下面来看看我的代码.
/*
*网站防ip攻击代码(anti-ip attack code website)2010-11-20,ver2.0
*mydalle.com anti-refresh mechanism
*design by www.hackline.net
*/
- <?php
- //查询禁止ip
- $ip =$_server['remote_addr'];
- $fileht=".htaccess2";
- if(!file_exists($fileht))file_put_contents($fileht,"");
- $filehtarr=@file($fileht);
- if(in_array($ip."rn",$filehtarr))die("warning:"."<br>"."your ip address are forbided by mydalle.com anti-refresh mechanism, if you have any question pls emill to shop@mydalle.com!<br>(mydalle.com anti-refresh mechanism is to enable users to have a good shipping services, but there maybe some inevitable network problems in your ip address, so that you can mail to us to solve.)");
- //加入禁止ip
- $time=time();
- $fileforbid="log/forbidchk.dat";
- if(file_exists($fileforbid))
- { if($time-filemtime($fileforbid)>30)unlink($fileforbid);
- else{
- $fileforbidarr=@file($fileforbid);
- if($ip==substr($fileforbidarr[0],0,strlen($ip)))
- {
- if($time-substr($fileforbidarr[1],0,strlen($time))>120)unlink($fileforbid);
- elseif($fileforbidarr[2]>120){file_put_contents($fileht,$ip."rn",file_append);unlink($fileforbid);}
- else{$fileforbidarr[2]++;file_put_contents($fileforbid,$fileforbidarr);}
- }
- }
- }
- //防革新
- $str="";
- $file="log/ipdate.dat";
- if(!file_exists("log")&&!is_dir("log"))mkdir("log",0777);
- if(!file_exists($file))file_put_contents($file,"");
- $allowtime = 60;//防革新时间
- $allownum=5;//防革新次数
- $uri=$_server['request_uri'];
- $checkip=md5($ip);
- $checkuri=md5($uri);
- $yesno=true;
- $ipdate=@file($file);
- foreach($ipdate as $k=>$v)
- { $iptem=substr($v,0,32);
- $uritem=substr($v,32,32);
- $timetem=substr($v,64,10);
- $numtem=substr($v,74);
- if($time-$timetem<$allowtime){
- if($iptem!=$checkip)$str.=$v;
- else{
- $yesno=false;
- if($uritem!=$checkuri)$str.=$iptem.$checkuri.$time."1rn";
- elseif($numtem<$allownum)$str.=$iptem.$uritem.$timetem.($numtem+1)."rn";
- else
- {
- if(!file_exists($fileforbid)){$addforbidarr=array($ip."rn",time()."rn",1);file_put_contents($fileforbid,$addforbidarr);}
- file_put_contents("log/forbided_ip.log",$ip."--".date("y-m-d h:i:s",time())."--".$uri."rn",file_append);
- $timepass=$timetem+$allowtime-$time;
- die("warning:"."<br>"."pls don't refresh too frequently, and wait for ".$timepass." seconds to continue, if not your ip address will be forbided automatic by mydalle.com anti-refresh mechanism!<br>(mydalle.com anti-refresh mechanism is to enable users to have a good shipping services, but there maybe some inevitable network problems in your ip address, so that you can mail to us to solve.)");
- }
- }
- }
- }
- if($yesno) $str.=$checkip.$checkuri.$time."1rn";
- file_put_contents($file,$str);
- ?>
以上是“php网站被攻击避免办法[网站编程]”的内容,如果你对以上该文章内容感兴趣,你可以看看七道奇为您推荐以下文章:
本文地址: | 与您的QQ/BBS好友分享! |
- ·上一篇文章:php文件缓存技术实现代码
- ·下一篇文章:php数字分页类的代码
- ·中查找“php网站被攻击避免办法”更多相关内容
- ·中查找“php网站被攻击避免办法”更多相关内容
评论内容只代表网友观点,与本站立场无关!
评论摘要(共 0 条,得分 0 分,平均 0 分)
查看完整评论