<?php
empty($_SERVER['HTTP_VIA']) or exit('Access Denied');
header("content-type:text/html;charset=utf-8;");
$seconds =2;// 刷新時間間隔 [秒]
$refresh =5;//刷新次數
$waitTime=10; //超頻後多久可以訪問
//設置監控變量
$cur_time = time();
session_start();
if(isset($_SESSION['last_time'])){
$_SESSION['refresh_times']+=1;
}
else
{
//第一次運行
$_SESSION['refresh_times']=1;
$_SESSION['last_time']= $cur_time;
}
//處理監控結果
if( isset($_SESSION['suoding']) && $cur_time - $_SESSION['suoding'] < $waitTime
||
$cur_time - $_SESSION['last_time'] < $seconds){
if($_SESSION['refresh_times'] >= $refresh){ //時間段內超頻,下次訪問退出。
$_SESSION['suoding'] = $cur_time;
exit('檢測到CC攻擊,正在進行瀏覽器安全檢查!');
}
}else{
//沒超頻,歸零, if裏的超頻了就沒歸零一直累積。
$_SESSION['refresh_times']=0;
$_SESSION['last_time']= $cur_time;
}
echo "超頻刷新了:".$_SESSION['refresh_times']."次,可以訪問!";
僅供學習參考,如有不妥,歡迎評論指正。共同學習。