PHP防CC攻击代码

2018年6月9日23:28:10 发表评论 1,708 人围观
<?php  

		
		
//代理IP直接退出  

		
		
emptyempty($_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;  		
  

		
}  

		
		
?> 

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: