PHP判斷搜索引擎蜘蛛并自動(dòng)記憶到文件的代碼
更新時(shí)間:2012年02月04日 14:51:18 作者:
為了記憶百度蜘蛛的行蹤,寫了以下的PHP函數(shù),分兩個(gè)函數(shù),一個(gè)是判斷蜘蛛名稱,一個(gè)是記憶蜘蛛到文件,可以自己看一下
復(fù)制代碼 代碼如下:
function write_naps_bot(){
$useragent=get_naps_bot();
// echoExit($useragent);
if ($useragent=="false") return FALSE ;
date_default_timezone_set("Asia/Shanghai");
$date=date("Y-m-d H:i:s");
$ip=$_SERVER[REMOTE_ADDR];
$url="http://".$_SERVER[HTTP_HOST].$_SERVER[REQUEST_URI];
// echoExit($url);轉(zhuǎn)載注明www.chhua.com
if (!file_exists("./log/bot.html")){
$botfile=fopen("./log/bot.html", "w");
$fileHeader="<head>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />
<title>訪問查看</title>
</head>
<a href=\"../?action=delbot\">刪除日志</a><hr>
";
// echoExit($botfile);轉(zhuǎn)載注明www.chhua.com
fputs($botfile, $fileHeader);
fclose($botfile);
}else
{ $filesize=filesize("./log/bot.html");
if ($filesize>=100000){
$botfile=fopen("./log/bot.html", "w");
$fileHeader="<head>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />
<title>訪問查看</title>
</head>
<a href=\"../?action=delbot\">刪除日志</a><hr>
";
fputs($botfile, $fileHeader);
fclose($botfile);
}else {
$botfile=fopen("./log/bot.html", "a+");
}
//$size="<b>當(dāng)前文件大小為:</b>".$filesize."<br>";轉(zhuǎn)載注明www.chhua.com
$useragent="<b>USER:</b>".$useragent."<Br>";
$date="<b>TIME:</b>".$date."<Br>";
$ip="<b>IP:</b>".$ip."<Br>";
$url="<b>URL:</b><a href='$url' target='_blank'>".$url."</a><Br><Br>";
$fileStr=$useragent.$date.$ip.$url;
fputs($botfile, $fileStr);
fclose($botfile);
}
}
function get_naps_bot() {
$useragent = strtolower($_SERVER['HTTP_USER_AGENT']);
if(strpos($useragent, 'googlebot') !== false){
return '<font color=blue>Googlebot</font>';
}
if(strpos($useragent, 'msnbot') !== false){
return 'MSNbot';
}
if(strpos($useragent, 'slurp') !== false){
return '<font color=green>Yahoobot</font>';
}
if(strpos($useragent, 'baiduspider') !== false){
return '<font color=red>Baiduspider</font>';
}
if(strpos($useragent, 'sohu-search') !== false){
return 'Sohubot';
}
if(strpos($useragent, 'lycos') !== false){
return 'Lycos';
}
if(strpos($useragent, 'robozilla') !== false){
return 'Robozilla';
}
return "false";
}
您可能感興趣的文章:
- PHP寫的獲取各搜索蜘蛛爬行記錄代碼
- php 判斷訪客是否為搜索引擎蜘蛛的函數(shù)代碼
- PHP屏蔽蜘蛛訪問代碼及常用搜索引擎的HTTP_USER_AGENT
- 用php實(shí)現(xiàn)讓頁(yè)面只能被百度gogole蜘蛛訪問的方法
- 發(fā)款php蜘蛛統(tǒng)計(jì)插件只要有mysql就可用
- 使用PHP實(shí)現(xiàn)蜘蛛訪問日志統(tǒng)計(jì)
- PHP判斷來(lái)訪是搜索引擎蜘蛛還是普通用戶的代碼小結(jié)
- 發(fā)款php蜘蛛統(tǒng)計(jì)插件只要有mysql就可用
- 根據(jù)user-agent判斷蜘蛛代碼黑帽跳轉(zhuǎn)代碼(js版與php版本)
- 利用php抓取蜘蛛爬蟲痕跡的示例代碼
相關(guān)文章
php實(shí)現(xiàn)發(fā)送微信模板消息的方法
這篇文章主要介紹了php實(shí)現(xiàn)發(fā)送微信模板消息的方法,實(shí)例分析了php操作curl及自定義模板消息的實(shí)現(xiàn)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-03-03PHP進(jìn)階學(xué)習(xí)之垃圾回收機(jī)制詳解
這篇文章主要介紹了PHP進(jìn)階學(xué)習(xí)之垃圾回收機(jī)制,詳細(xì)分析了php垃圾回收機(jī)制的概念、原理及對(duì)性能的影響,需要的朋友可以參考下2019-06-06PHP高并發(fā)高負(fù)載下的3種實(shí)戰(zhàn)場(chǎng)景解決方法示例
這篇文章主要為大家介紹了PHP高并發(fā)高負(fù)載下的3種實(shí)戰(zhàn)場(chǎng)景解決方法示例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-05-05Referer原理與圖片防盜鏈實(shí)現(xiàn)方法詳解
這篇文章主要介紹了Referer原理與圖片防盜鏈實(shí)現(xiàn)方法,結(jié)合實(shí)例形式詳細(xì)分析了Referer頭信息原理與圖片防盜鏈判定、實(shí)現(xiàn)方法,并附帶一個(gè)Http請(qǐng)求封裝類,需要的朋友可以參考下2019-07-07