欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

php記錄搜索引擎爬行記錄的實(shí)現(xiàn)代碼

 更新時(shí)間:2018年03月02日 16:36:10   投稿:mrr  
這篇文章主要介紹了php記錄搜索引擎爬行記錄的實(shí)現(xiàn)代碼,然后在文中給大家補(bǔ)充介紹了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的根目錄路徑,意思就是說(shuō)robotslogs.txt文件是放在根目錄下的。

通過(guò)get_naps_bot()獲取蜘蛛爬行記錄,然后在通過(guò)addslashes處理一下,將數(shù)據(jù)存儲(chǔ)于變量$tlc_thispage中。

fopen打開(kāi)robotslogs.txt文件,將數(shù)據(jù)通過(guò)函數(shù)fwrite寫(xiě)入,在通過(guò)函數(shù)fclose關(guān)閉就可以了。

因?yàn)槲矣X(jué)得沒(méi)必要,所以把自己網(wǎng)站上的代碼刪除了,所以也沒(méi)有效果示例了。

PS:php獲取各搜索蜘蛛爬行記錄的代碼

支持如下的搜索引擎:Baidu,Google,Bing,Yahoo,Soso,Sogou,Yodao爬行網(wǎng)站的記錄!

代碼:

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

總結(jié)

以上所述是小編給大家介紹的php記錄搜索引擎爬行記錄,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!

相關(guān)文章

最新評(píng)論