<?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防止刷新(流量攻击)的一段代码的更多相关文章

  1. [故障公告]14:39-15:39博客站点部分负载均衡遭遇3次20G以上的流量攻击

      非常抱歉,今天下午14:39-15:39左右,博客站点的部分负载均衡遭遇3次20G以上的流量攻击,造成很多用户不能正常访问.由此给您带来麻烦,请您谅解. 攻击的过程是这样的: 14:39,第1次攻 ...

  2. DDOS攻击(流量攻击)防御步骤

    DDOS全名是Distributed Denial of service (分布式拒绝服务攻击),很多DOS攻击源一起攻击某台服务器就组成了DDOS攻击,DDOS 最早可追溯到1996年最初,在中国2 ...

  3. 云计算之路-阿里云上:攻击又来了,4个IP分别遭遇超过30G的流量攻击

    继5月13日下午被攻击之后,今天下午,攻击又肆无忌惮地来了,14:35.14:39.14:40.14:41 ,依次有4个IP遭遇超过30G的流量攻击,被阿里云“云盾”关进“黑洞”,造成被攻击IP上的站 ...

  4. 常见的 CSRF、XSS、sql注入、DDOS流量攻击

    CSRF攻击 :跨站请求伪造攻击 ,CSRF全名是Cross-site request forgery,是一种对网站的恶意利用,CSRF比XSS更具危险性 攻击者一般会使用吸引人的图片去引导用户点击进 ...

  5. 什么是高防服务器?如何搭建DDOS流量攻击防护系统

    关于高防服务器的使用以及需求,从以往的联众棋牌到目前发展迅猛的手机APP棋牌,越来越多的游戏行业都在使用高防服务器系统,从2018年1月到11月,国内棋牌运营公司发展到了几百家. 棋牌的玩法模式从之前 ...

  6. 如何防御网站被ddos攻击 首先要了解什么是流量攻击

    什么是DDOS流量攻击?我们大多数人第一眼看到这个DDOS就觉得是英文的,有点难度,毕竟是国外的,其实简单通俗来讲,DDOS攻击是利用带宽的流量来攻击服务器以及网站. 举个例子,服务器目前带宽是100 ...

  7. nginx解决服务器宕机、解决跨域问题、配置防盗链、防止DDOS流量攻击

    解决服务器宕机 配置nginx.cfg配置文件,在映射拦截地址中加入代理地址响应方案 location / { proxy_connect_timeout 1; proxy_send_timeout ...

  8. Nginx防止DDOS流量攻击

    DDOS流量攻击:频繁的发送请求,造成宽带占用,其他客户端无法访问                Nginx解决DDOS流量攻击,利用limit_req_zone限制请求次数    limit_con ...

  9. PHP禁止同一IP频繁访问以防止网站被防攻击或采集的代码

    PHP禁止同一IP频繁访问以防止网站被防攻击或采集的代码 <?php /* *通过禁止IP频繁访问防止网站被防攻击代码*design by www.scutephp.com*/header('C ...

随机推荐

  1. 转:ASP.NET MVC + EF 更新的几种方式

    1.常用 db.Entry(实体).State = EntityState.Modified;db.SaveChanges(); 2.指定更新 db.Configuration.ValidateOnS ...

  2. 关于前后台交互生成json区别

    如何返回[object{xx:{}}]这种数组型json在服务器端return $arr[]=m;像这种都可以产生[Object { 0="9", 1="8", ...

  3. Linux绑定双网卡

    Linux绑定双网卡 1. 配置参数文件 版本在centos6以下在/etc/modproe.conf文件中配置,版本是centos6.x或以上在/etc/modproe.d/目录下配置. 2.    ...

  4. zookeeper session tracker机制分析

    说到zookeeper session管理 ,免不了要问 什么是session? session id/session是如何产生的? session 信息如何存储? 本文以session tracke ...

  5. int[] List<int> 排序

    ; List<,,,,,,}; ,,,,}; List<int> result = allingInts.ToList(); result.Sort(); allingInts = ...

  6. .Net Framework 4.5.2 on Windows 10

    I was using Visual Studio 2013 to create a new solution, could not select ".NET Framework 4.5.2 ...

  7. swiper有时候不能自动滚动的问题

    <script type="text/javascript"> $(function(){ var swiper = new Swiper('.swiper-conta ...

  8. MySQL-profiling的使用

    分析SQL执行带来的开销是优化SQL的重要手段.在MySQL数据库中,可以通过配置profiling参数来启用SQL剖析.该参数可以在全局和session级别来设置.对于全局级别则作用于整个MySQL ...

  9. Java NIO学习(一)

    Java NIO 由以下几个核心部分组成: Channels Buffers Selectors 虽然Java NIO 中除此之外还有很多类和组件,但在我看来,Channel,Buffer 和 Sel ...

  10. Caused by: org.springframework.core.NestedIOException: ASM ClassReader failed to parse class file

    springframework.version  3.2.6.RELEASE jdk 1.8