前几天由于被人恶意CC攻击导致图片空间的请求量过高,关闭了。网站空间并没有什么大碍,但是被人恶意攻击网站是在是太不爽了,于是上网找了一个防止连续快速刷新网页的代码 这个代码不止可以防CC攻击,也可以防止各种东西 只要加入header就可以统统使用了,灰常给力,废话不多说了,直接上代码
<?php
/**
* @author 天涯
* mail@phpha.com
*/
//代理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;
}
?>
732974 596564Hey, you used to write magnificent, but the last several posts have been kinda boringK I miss your super writings. Past several posts are just a little bit out of track! come on! 645555
2018年8月15日 22:16跳转至攻击者服务器地址要改吗?
2015年1月1日 19:04随你便啦
2015年1月1日 19:29