PHP版的捕捉搜索引擎蜘蛛爬行的代码

<?php
/*
以下提供给大家的是PHP版的捕捉搜索引擎蜘蛛爬行的代码。
我们可以通过生成的文本文件查看每天都有哪几种搜索引擎蜘蛛爬行站点以及爬行频率,
便于大家了解蜘蛛动向。
但是,从SEO工具需求角度来说,
这段代码实现的功能还是很有局限性,从我个人需求而言,我希望能体现更多的信息,
比如:蜘蛛爬行的页面URL、返回的状态码、每日爬行持续多长时间等等,甚至可以汇总于数据库中便于随时查询。
因此,强烈呼吁编程高手开发数据库版的捕捉蜘蛛的程序。
*/
/*
使用方法:
把以下代码粘贴到你想监控的页面php代码的之间的开头或结尾即可(也可以放在模板文件内)
*/
function get_naps_bot()
{
  $useragent = strtolower($_SERVER['HTTP_USER_AGENT']);
 
  if (strpos($useragent, 'googlebot') !== false){
    return 'Googlebot';
  }
 
  if (strpos($useragent, 'msnbot') !== false){
    return 'MSNbot';
  }
 
  if (strpos($useragent, 'slurp') !== false){
    return 'Yahoobot';
  }
 
  if (strpos($useragent, 'baiduspider') !== false){
    return 'Baiduspider';
  }
 
  if (strpos($useragent, 'sohu-search') !== false){
    return 'Sohubot';
  }
 
  if (strpos($useragent, 'lycos') !== false){
    return 'Lycos';
  }
 
  if (strpos($useragent, 'robozilla') !== false){
    return 'Robozilla';
  }
  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="robotlog.txt";
  $time=nowtime();
  $data=fopen($file,"a");
  fwrite($data,"Timetime robotsearchbot URLtlc_thispage\n");
  fclose($data);
}
?>
一下是生成的robots里的东西!
Time:2008-04-20.2:29:45 robot:Googlebot URL:Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)
Time:2008-04-20.4:27:20 robot:Googlebot URL:Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)
Time:2008-04-20.9:52:23 robot:Googlebot URL:Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)
Time:2008-04-20.14:10:44 robot:Googlebot URL:Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)
Time:2008-04-20.16:07:04 robot:Googlebot URL:Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)
Time:2008-04-20.18:03:08 robot:Googlebot URL:Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)
Time:2008-04-20.19:59:46 robot:Googlebot URL:Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)
Time:2008-04-20.23:52:03 robot:Googlebot URL:Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)
有人能帮我解释下吧!看的不是很懂!特别是URL:Mozilla/5.0 这个是什么意思?
代码是一个仁兄提供的,在此感谢他!

本文来自: 站长创投(www.Adminvc.com) 详细出处:http://www.adminvc.com/view_112503_6.html

评论

此博客中的热门博文

你的妈妈已经等了二十几年

时间管理:每天挤出一小时

教您如何认识植柔皮,头层皮革,修面皮革,油蜡皮、水染皮、摔纹皮、纳帕皮、打蜡皮、压花皮、修面皮、漆光皮、磨砂皮、贴膜皮