php記錄搜尋引擎爬行過程方法詳解

來源:互聯網
上載者:User
這次給大家帶來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 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中文網其它相關文章!

推薦閱讀:

php讀取本地json檔案有哪些方法

php有哪些方法可以輸出json對象的值

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.