亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

php記錄搜索引擎爬行記錄的實現代碼

 更新時間:2018年03月02日 16:36:10   投稿:mrr  
這篇文章主要介紹了php記錄搜索引擎爬行記錄的實現代碼,然后在文中給大家補充介紹了php獲取各搜索蜘蛛爬行記錄的代碼,需要的朋友可以參考下

下面是完整代碼:

//記錄搜索引擎爬行記錄 $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 chabaoo.cn
*/
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="chabaoo.cn.txt"; 
$time=nowtime(); 
$data=fopen($file,"a"); 
fwrite($data,"Time:$time robot:$searchbot URL:$tlc_thispage\n"); 
fclose($data); 
} 
?>

總結

以上所述是小編給大家介紹的php記錄搜索引擎爬行記錄,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網站的支持!

相關文章

最新評論