EMLOG防CC代码

497次阅读
没有评论

共计 1194 个字符,预计需要花费 3 分钟才能阅读完成。

 代码一:
<?php
function sheli_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 sheli_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 sheli_cc();

 
正文完
 
评论(没有评论)