php实现cc攻击防御和防止快速刷新页面示例
程序员文章站
2022-06-29 19:06:35
复制代码 代码如下:
<?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;
}
?>
复制代码 代码如下:
<?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;
}
?>
下一篇: 掌握科学健身方法 健身效果事半工倍