php防止刷新(流量攻击)的一段代码
<?php
//查询禁止IP
$ip =$_SERVER['REMOTE_ADDR'];
$fileht=".htaccess2";
if(!file_exists($fileht))file_put_contents($fileht,"");
$filehtarr=@file($fileht);
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!");
//加入禁止IP
$time=time();
$fileforbid="log/forbidchk.dat";
if(file_exists($fileforbid)){
if($time-filemtime($fileforbid)>60){
unlink($fileforbid);
}else{
$fileforbidarr=@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);
}
}
}
}
//防刷新
$str="";
$file="log/ipdate.dat";
if(!file_exists("log")&&!is_dir("log"))mkdir("log",0777);
if(!file_exists($file))file_put_contents($file,"");
$allowTime = 120;//防刷新时间
$allowNum=10;//防刷新次数
$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."1\r\n";
elseif($numtem<$allowNum)$str.=$iptem.$uritem.$timetem.($numtem+1)."\r\n";
else{
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);
$timepass=$timetem+$allowTime-$time;
die("Warning:"."<br>"."Sorry,you are forbided by refreshing frequently too much, Pls wait for ".$timepass." seconds to continue!");
}
}
}
}
if($yesno) $str.=$checkip.$checkuri.$time."1\r\n";
file_put_contents($file,$str);
php防止刷新(流量攻击)的一段代码的更多相关文章
- [故障公告]14:39-15:39博客站点部分负载均衡遭遇3次20G以上的流量攻击
非常抱歉,今天下午14:39-15:39左右,博客站点的部分负载均衡遭遇3次20G以上的流量攻击,造成很多用户不能正常访问.由此给您带来麻烦,请您谅解. 攻击的过程是这样的: 14:39,第1次攻 ...
- DDOS攻击(流量攻击)防御步骤
DDOS全名是Distributed Denial of service (分布式拒绝服务攻击),很多DOS攻击源一起攻击某台服务器就组成了DDOS攻击,DDOS 最早可追溯到1996年最初,在中国2 ...
- 云计算之路-阿里云上:攻击又来了,4个IP分别遭遇超过30G的流量攻击
继5月13日下午被攻击之后,今天下午,攻击又肆无忌惮地来了,14:35.14:39.14:40.14:41 ,依次有4个IP遭遇超过30G的流量攻击,被阿里云“云盾”关进“黑洞”,造成被攻击IP上的站 ...
- 常见的 CSRF、XSS、sql注入、DDOS流量攻击
CSRF攻击 :跨站请求伪造攻击 ,CSRF全名是Cross-site request forgery,是一种对网站的恶意利用,CSRF比XSS更具危险性 攻击者一般会使用吸引人的图片去引导用户点击进 ...
- 什么是高防服务器?如何搭建DDOS流量攻击防护系统
关于高防服务器的使用以及需求,从以往的联众棋牌到目前发展迅猛的手机APP棋牌,越来越多的游戏行业都在使用高防服务器系统,从2018年1月到11月,国内棋牌运营公司发展到了几百家. 棋牌的玩法模式从之前 ...
- 如何防御网站被ddos攻击 首先要了解什么是流量攻击
什么是DDOS流量攻击?我们大多数人第一眼看到这个DDOS就觉得是英文的,有点难度,毕竟是国外的,其实简单通俗来讲,DDOS攻击是利用带宽的流量来攻击服务器以及网站. 举个例子,服务器目前带宽是100 ...
- nginx解决服务器宕机、解决跨域问题、配置防盗链、防止DDOS流量攻击
解决服务器宕机 配置nginx.cfg配置文件,在映射拦截地址中加入代理地址响应方案 location / { proxy_connect_timeout 1; proxy_send_timeout ...
- Nginx防止DDOS流量攻击
DDOS流量攻击:频繁的发送请求,造成宽带占用,其他客户端无法访问 Nginx解决DDOS流量攻击,利用limit_req_zone限制请求次数 limit_con ...
- PHP禁止同一IP频繁访问以防止网站被防攻击或采集的代码
PHP禁止同一IP频繁访问以防止网站被防攻击或采集的代码 <?php /* *通过禁止IP频繁访问防止网站被防攻击代码*design by www.scutephp.com*/header('C ...
随机推荐
- JS给swf传参数
不仅可以用flashvars ="name=12&age=23" 还可以在指定swf地址时传参数src="test.swf?name=12&age=23& ...
- 解决在.ashx文件中判断Session 总是NULL的方法
实现IHttpHandler接口的同时必须继承IRequiresSessionState接口,才能拿到session public class HttpHandler: IHttpHandler, I ...
- 通过iphone蓝牙与经过苹果MFI授权认证的硬件通讯,传输图片(转)
http://blog.csdn.net/hwj2012/article/details/7883711 相关: http://blog.csdn.net/xufeidll/article/detai ...
- C语言课本实例
1. 将一维数组的内容倒顺 #include <stdio.h>void func(int *s,int n){ int i,temp; for(i=0;i<n/2;i++) { t ...
- POJ 1041问题描述
Description Little Johnny has got a new car. He decided to drive around the town to visit his friend ...
- zabbix监控activemq队列脚本
公司业务使用activemq5.9.1消息队列,由于队列阻塞导致程序端口无响应,并且telnet无法连通.经过over 1 hour的排查,最终定位原因activemq导致.遂写了一个监控active ...
- Android java判断字符串包含某个字符段(或替换)
String str = "; ) { System.out.println("包含该字符串"); }
- [BS-20] 导航控制器和视图控制器在添加控制器的区别
导航控制器和视图控制器在添加控制器的区别 1. 因导航控制器拥有导航栈,有一个普通视图控制器都没有的数组viewControllers,加入该数组中的视图控制器默认以push的方式进入导航栈.导航控制 ...
- linux操作技巧
1. 打开终端 ctrl+ALT+T 新终端 ctrl+shift+T 原有终端新页面 2. 忘记root密码 redhat下 单用户进入grub 在核心文件后加"single&qu ...
- python eval
缘起 小例子 def test_1(val): print "val", val, type(val) def test_2(val): print ) if __name__ = ...