下面是完整代碼:
//記錄搜索引擎爬行記錄 $searchbot = get_naps_bot();
if ($searchbot)
{ $tlc_thispage = addslashes($_SERVER['HTTP_USER_AGENT']);
$url = $_SERVER['HTTP_REFERER'];
$file = WEB_PATH.'robotslogs.txt';
$date = date('Y-m-d H:i:s');
$data = fopen($file,'a');
fwrite($data,"Time:$date robot:$searchbot URL:$tlc_thispage/r/n");
fclose($data);
}
WEB_PATH為index.PHP下define的根目錄路徑,意思就是說robotslogs.txt文件是放在根目錄下的。
通過get_naps_bot()
獲取蜘蛛爬行記錄,然后在通過addslashes處理一下,將數據存儲于變量$tlc_thispage中。
fopen打開robotslogs.txt文件,將數據通過函數fwrite寫入,在通過函數fclose關閉就可以了。
因為我覺得沒必要,所以把自己網站上的代碼刪除了,所以也沒有效果示例了。
PS:php獲取各搜索蜘蛛爬行記錄的代碼
支持如下的搜索引擎:Baidu,Google,Bing,Yahoo,Soso,Sogou,Yodao爬行網站的記錄!
代碼:
?php
/**
* 獲取搜索引擎爬行記錄
* edit by www.jb51.net
*/
function get_naps_bot()
{
$useragent = strtolower($_SERVER['HTTP_USER_AGENT']);
if (strpos($useragent, 'googlebot') !== false){
return 'Google';
}
if (strpos($useragent, 'baiduspider') !== false){
return 'Baidu';
}
if (strpos($useragent, 'msnbot') !== false){
return 'Bing';
}
if (strpos($useragent, 'slurp') !== false){
return 'Yahoo';
}
if (strpos($useragent, 'sosospider') !== false){
return 'Soso';
}
if (strpos($useragent, 'sogou spider') !== false){
return 'Sogou';
}
if (strpos($useragent, 'yodaobot') !== false){
return 'Yodao';
}
return false;
}
function nowtime(){
$date=date("Y-m-d.G:i:s");
return $date;
}
$searchbot = get_naps_bot();
if ($searchbot) {
$tlc_thispage = addslashes($_SERVER['HTTP_USER_AGENT']);
$url=$_SERVER['HTTP_REFERER'];
$file="www.jb51.net.txt";
$time=nowtime();
$data=fopen($file,"a");
fwrite($data,"Time:$time robot:$searchbot URL:$tlc_thispage\n");
fclose($data);
}
?>
總結
以上所述是小編給大家介紹的php記錄搜索引擎爬行記錄,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網站的支持!
您可能感興趣的文章:- Mysql實現簡易版搜索引擎的示例代碼
- MySQL全文索引實現簡單版搜索引擎實例代碼
- 詳細介紹基于MySQL的搜索引擎MySQL-Fullltext
- scrapy+flask+html打造搜索引擎的示例代碼
- python基于搜索引擎實現文章查重功能
- Python實戰之手寫一個搜索引擎
- Python大批量搜索引擎圖像爬蟲工具詳解
- 360搜索引擎自動收錄php改寫方案
- Python無損音樂搜索引擎實現代碼
- 基于 Mysql 實現一個簡易版搜索引擎