301重定向用防止cc的示例:
采用301重定向方式,降低CC攻擊的效果,在對應的文件中添加以下php代碼:
<?php
empty($_SERVER['HTTP_VIA']) or exit('Access Denied');
$seconds = 10; //時間段[秒]
$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){
//301重定向驗證
$url='http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
$msg=mb_convert_encoding("<title>安全檢查</title><h3>檢測到CC攻擊,正在進行瀏覽器安全檢查!</h3>","UTF-8","GBK");
exit($msg."<meta http-equiv='refresh' content='5;url={$url}'>");//5是定時跳轉的時間,后期可以根據時間段調整跳轉時間
}
}else{
$_SESSION['refresh_times'] = 0;
$_SESSION['last_time'] = $cur_time;
}
?>