下面是完整代碼:
php;" style="margin: 3px auto 0px; padding: 0px 0px 0px 5px; outline: none; background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; width: 640px; line-height: 20px; clear: both; border-left: 3px solid rgb(108, 226, 108);"> //記錄搜索引擎爬行記錄 $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處理一下,將數(shù)據(jù)存儲(chǔ)于變量$tlc_thispage中。
fopen打開robotslogs.txt文件,將數(shù)據(jù)通過函數(shù)fwrite寫入,在通過函數(shù)fclose關(guān)閉就可以了。
因?yàn)槲矣X得沒必要,所以把自己網(wǎng)站上的代碼刪除了,所以也沒有效果示例了。
PS:php獲取各搜索蜘蛛爬行記錄的代碼
支持如下的搜索引擎:Baidu,Google,Bing,Yahoo,Soso,Sogou,Yodao爬行網(wǎng)站的記錄!
代碼:
<?php /** * 獲取搜索引擎爬行記錄 * edit by www.zmynmublwnt.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.zmynmublwnt.cn.txt"; $time=nowtime(); $data=fopen($file,"a"); fwrite($data,"Time:$time robot:$searchbot URL:$tlc_thispage\n"); fclose($data); } ?>
總結(jié)
以上所述是小編給大家介紹的php記錄搜索引擎爬行記錄,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)服務(wù)器之家網(wǎng)站的支持!