php避免网站被攻击办法
发布时间:2022-07-05 16:45:26 所属栏目:PHP教程 来源:互联网
导读:最近网站经常被攻击,后来想到了一个利用php来防止网站受攻击的办法,下面是我的代码,代码不是最好的,根据自己的需求来做,下面来看看我的代码. /* *网站防ip攻击代码(anti-ip attack code website)2010-11-20,ver2.0 *mydalle.com anti-refresh mechanism *des
最近网站经常被攻击,后来想到了一个利用php来防止网站受攻击的办法,下面是我的代码,代码不是最好的,根据自己的需求来做,下面来看看我的代码. /* *网站防ip攻击代码(anti-ip attack code website)2010-11-20,ver2.0 *mydalle.com anti-refresh mechanism *design by www.phpfensi.com */ "."your ip address are forbided by mydalle.com anti-refresh mechanism, if you have any question pls emill to shop@mydalle.com! (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($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); 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 { die("warning:"." "."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! (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.)"); } //开源代码phpfensi.com } } } if($yesno) $str.=$checkip.$checkuri.$time."1rn"; file_put_contents($file,$str); ?> (编辑:应用网_丽江站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |