防止采集的一個小程序 By 暖月
2015.09.10 | 15閱讀 | 0條評論 | 未命名
功能描述:
默認設置完成24小時內僅僅允許單用戶瀏覽5000個頁面。
引用:
<?
//參數設置
$settime="86400"; //控制多久的采集數量,單位秒
$setsum="5000"; //在這個時間內最多允許采集多少條
$setnotic="細水長流,采集因過量而被終止,建議24小時后重新嘗試。"; //如果條件吻合,給出的提示
$seturl="http://www.minblog.cn/"; //提示之后轉移的頁面
//參數設置
ob_start();
$utime=$HTTP_COOKIE_VARS["utime"];
$usee=$HTTP_COOKIE_VARS["usee"];
if(!$utime){
setcookie("utime", time(), time()+$settime);
setcookie("usee", 1, time()+$settime);
}elseif($utime>=(time()-$settime) and $usee>=$setsum){
echo "<script>alert('".$setnotic."');location.href='".$seturl."';</script>"; //說明:如果是html調用(使用方法 2),把本行刪除,下一行開頭的//刪除即可
// echo "alert('".$setnotic."');location.href='".$seturl."';";
}elseif($utime>=(time()-$settime) and $usee<$setsum){
setcookie("usee", $usee+1, time()+$settime);
}else{
setcookie("utime", time(), time()+$settime);
}
?>
使用方法:
1、php文件直接加入
保存文件為 ****.php
在你要套用的php程序頁面頂部加入
引用:
<?
include "****.php";
?>
即可
2、html頁面加入
保存文件為 ****.php ,在html模板中加入以下代碼。注意文件路徑
引用:
<script src="****.php" type="text/javascript"></script>
適用范圍:
Discuz!,PHPWind...
發(fā)表評論