当前位置:首页 » 好文分享 » 详情

最新EMLOG程序防CC攻击代码

将下面代码插入在module.php文件内:

代码一
<?php
function maple_cc(){
       session_start();
$timestampcc = time();
$cc_nowtime = $timestampcc;
if(isset($_SESSION['cc_lasttime'])){$cc_lasttime = $_SESSION['cc_lasttime'];$cc_times = $_SESSION['cc_times']+1;$_SESSION['cc_times'] = $cc_times;
}else{$cc_lasttime = $cc_nowtime;$cc_times = 1;$_SESSION['cc_times'] = $cc_times;$_SESSION['cc_lasttime'] = $cc_lasttime;} 
if(($cc_nowtime-$cc_lasttime)<60){if($cc_times>=3){header(sprintf('Location:%s', 'http://127.0.0.1'));exit;}//60秒内刷新3次以上可能为cc攻击
}else{$cc_times = 0;$_SESSION['cc_lasttime'] = $cc_nowtime;$_SESSION['cc_times'] = $cc_times;}
}
?>

代码二
<?php
function maple_cc(){
        //代理IP直接退出
        empty($_SERVER['HTTP_VIA']) or exit('Access Denied');
        //防止快速刷新
        session_start();
        $seconds = '60'; //时间段[秒]
        $refresh = '3'; //刷新次数
        //设置监控变量
        $cur_time = time();
        if(isset($_SESSION['last_time'])){
                $_SESSION['refresh_times'] += 1;
        }else{
                $_SESSION['refresh_times'] = 1;
                $_SESSION['last_time'] = $cur_time;
        }
        //处理监控结果
        if($cur_time - $_SESSION['last_time'] < $seconds){
                if($_SESSION['refresh_times'] >= $refresh){
                        //跳转至攻击者服务器地址
                        header(sprintf('Location:%s', 'http://127.0.0.1'));
                        exit('Access Denied');
                }
        }else{
                $_SESSION['refresh_times'] = 0;
                $_SESSION['last_time'] = $cur_time;
        }
}
?>

然后在head.php文件的require_once View::getView('module');后面插入echo maple_cc();
打赏
X
打赏方式:
  • 支付宝
  • 微信
  • QQ红包

打开支付宝扫一扫
日期:2017年11月30日 20:27:59 星期四   分类:好文分享   浏览(29342)
本文地址:https://www.blogs.hk/post-2892.html   [百度已收录]
声明:本页信息由网友自行发布或来源于网络,真实性、合法性由发布人负责,请仔细甄别!本站只为传递信息,我们不做任何双方证明,也不承担任何法律责任。文章内容若侵犯你的权益,请联系本站删除!

留言咨询

自动获取QQ

昵称

邮箱

网址

      Copyright © 2024 博客之家 版权所有  
      關於本站免責聲明sitemap新站登錄