301重定向用防止cc的示例:
采用301重定向方式,降低CC攻擊的效果,在對應(yīng)的文件中添加以下php代碼:
<?php
empty($_SERVER['HTTP_VIA']) or exit('Access Denied');
$seconds = 10; //時間段[秒]
$refresh = 5; //刷新次數(shù)
//設(shè)置監(jiān)控變量
$cur_time = time();
if(isset($_SESSION['last_time'])){
$_SESSION['refresh_times'] += 1;
}else{
$_SESSION['refresh_times'] = 1;
$_SESSION['last_time'] = $cur_time;
}
//處理監(jiān)控結(jié)果
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是定時跳轉(zhuǎn)的時間,后期可以根據(jù)時間段調(diào)整跳轉(zhuǎn)時間
}
}else{
$_SESSION['refresh_times'] = 0;
$_SESSION['last_time'] = $cur_time;
}
?>