$7.49 .com domain with free InstantPage Website Builder$1.99 Web Hosting   捷飞网络官方淘宝店   Godaddy 优惠码
返回列表 发帖
分享到:




[PHP 语言] [分享]PHP版的记录/捕捉搜索引擎蜘蛛爬行log的代码

PHP版的捕捉搜索引擎蜘蛛爬行的代码
6 V' ]$ b5 `4 B2 K2 i
5 B* z3 ]; l( ]: }0 i3 W
- N4 b3 b" A+ V
  1. <?php
  2. /*
  3. 使用方法:
  4. 把以下代码粘贴到你想监控的页面php代码的之间的开头或结尾即可(也可以放在模板文件内)
  5. */
  6. function get_naps_bot()
  7. {
  8. $useragent = strtolower($_SERVER['HTTP_USER_AGENT']);

  9. if (strpos($useragent, 'googlebot') !== false){
  10. return 'Googlebot';
  11. }

  12. if (strpos($useragent, 'msnbot') !== false){
  13. return 'MSNbot';
  14. }

  15. if (strpos($useragent, 'slurp') !== false){
  16. return 'Yahoobot';
  17. }

  18. if (strpos($useragent, 'baiduspider') !== false){
  19. return 'Baiduspider';
  20. }

  21. if (strpos($useragent, 'sohu-search') !== false){
  22. return 'Sohubot';
  23. }

  24. if (strpos($useragent, 'lycos') !== false){
  25. return 'Lycos';
  26. }

  27. if (strpos($useragent, 'robozilla') !== false){
  28. return 'Robozilla';
  29. }


  30. return false;
  31. }


  32. function nowtime(){
  33. $date=date("Y-m-d.G:i:s");

  34. return $date;
  35. }


  36. $searchbot = get_naps_bot();

  37. if ($searchbot) {
  38. $tlc_thispage = addslashes($_SERVER['HTTP_USER_AGENT']);
  39. $url=$_SERVER['HTTP_REFERER'];
  40. $file="robotlog.txt";
  41. $time=nowtime();
  42. $data=fopen($file,"a");
  43. fwrite($data,"Time:$time robot:$searchbot URL:$tlc_thispage\n");
  44. fclose($data);
  45. }
  46. ?>
复制代码
! S  X3 B# _% N# v* u! \
1 b. x& Z- m/ M: Y; b
参考: 网络

美国VPS、域名代购:http://tu8l.taobao.com

返回列表
Namecheap
Namecheap.com - Cheap domain name registration, renewal and transfers - Free SSL Certificates - Web Hosting
互联网安全