php实现cc攻击防御和防止快速刷新页面示例
代码如下:
<?php //代理IP直接退出 empty($_SERVER['HTTP_VIA']) or exit('Access Denied'); //防止快速刷新 session_start(); $seconds = '3'; //时间段[秒] $refresh = '5'; //刷新次数 //设置监控变量 $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; } ?>
相关推荐
常言道 2020-05-25
Summer的小屋 2013-08-13
前端知识梳理 2019-11-01
展翅飞嵌入式之路 2017-03-24
xasdfg 2015-08-01
hedafighter0 2015-12-20
ARCHYang 2015-04-22
yunna0 2019-06-26
xasdfg 2012-04-29
Eleven的个人小站 2014-09-20
89284553 2014-03-12
yuanheiqng 2014-04-10
fengxu 2018-02-20
BillyThe 2016-01-06
迷题 2015-04-06
老男孩linux教育 2010-03-05
rise 2015-08-18
wmengbeyond 2012-04-21
ScienceExplorer 2010-12-20