防止采集的一個(gè)小程序 By 暖月
2015.09.10 | 7閱讀 | 0條評(píng)論 | 未命名
功能描述:
默認(rèn)設(shè)置完成24小時(shí)內(nèi)僅僅允許單用戶瀏覽5000個(gè)頁(yè)面。
引用:
<?
//參數(shù)設(shè)置
$settime="86400"; //控制多久的采集數(shù)量,單位秒
$setsum="5000"; //在這個(gè)時(shí)間內(nèi)最多允許采集多少條
$setnotic="細(xì)水長(zhǎng)流,采集因過(guò)量而被終止,建議24小時(shí)后重新嘗試。"; //如果條件吻合,給出的提示
$seturl="http://www.minblog.cn/"; //提示之后轉(zhuǎn)移的頁(yè)面
//參數(shù)設(shè)置
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>"; //說(shuō)明:如果是html調(diào)用(使用方法 2),把本行刪除,下一行開(kāi)頭的//刪除即可
// 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程序頁(yè)面頂部加入
引用:
<?
include "****.php";
?>
即可
2、html頁(yè)面加入
保存文件為 ****.php ,在html模板中加入以下代碼。注意文件路徑
引用:
<script src="****.php" type="text/javascript"></script>
適用范圍:
Discuz!,PHPWind...
發(fā)表評(píng)論