MENU

如何用PHP代码有效防CC攻击,让攻击者自食其果!

• May 30, 2020 • Read: 284 • 网站运维

通过程序攻击检测后,自动跳转至攻击者服务器地址127.0.0.1,让攻击者自食其果!

咱们直接上代码~

<?php  
empty($_SERVER['HTTP_VIA']) or exit('Access Denied');  //代理IP直接退出    
session_start();       
$seconds = '2'; //段秒        
$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;                  
}          
?> 

如何用PHP代码有效防CC攻击,让攻击者自食其果! - 原文链接:https://blog.isww.cn/archives/383/

Last Modified: June 24, 2021
Archives QR Code Tip
QR Code for this page
Tipping QR Code