郑州SEO/SEM

从事网站优化,网站推广,搜索引擎优化的研究!-Chw's BLOG.

« dedecms_织梦系统时间大全Google Adsense常见问题解答 »

可以捕捉各大搜索引擎蜘蛛的Php代码

1:把以下内容放在php文档<? ?>之间开头或结尾即可。

2:查看具体的搜索引擎机器人爬行纪录请访问程序中涉及的txt文档,大家可以自行修改路径。该文档内容包括蜘蛛爬行日期、时间、蜘蛛名称和网址。

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,"Time:$time robot:$searchbot URL:$tlc_thispage\n");
fclose($data);
}

访问记录实例:Time:2009-09-10.23:56:25 robot:Googlebot URL:Googlebot/2.1+(+http://www.google.com/bot.html)Time:2009-09-11.0:43:19 robot:Googlebot URL:Googlebot/2.1+(+http://www.google.com/bot.html)Time:2009-09-11.1:55:45 robot:Baiduspider URL:Baiduspider+(+http://www.baidu.com/search/spider.htm)Time:2009-09-11.3:03:40 robot:Yahoobot URL:Mozilla/5.0 (compatible; Yahoo! Slurp/3.0; http://help.yahoo.com/help/us/ysearch/slurp)Time:2009-09-11.4:49:59 robot:Googlebot URL:Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)Time:2009-09-11.7:25:21 robot:Yahoobot URL:Mozilla/5.0 (compatible; Yahoo! Slurp/3.0; http://help.yahoo.com/help/us/ysearch/slurp)Time:2009-09-11.9:15:57 robot:Googlebot URL:Googlebot/2.1+(+http://www.google.com/bot.html)Time:2009-09-11.9:24:23 robot:Googlebot URL:Googlebot/2.1+(+http://www.google.com/bot.html)Time:2009-09-11.9:40:00 robot:Baiduspider URL:Baiduspider+(+http://www.baidu.com/search/spider.htm)Time:2009-09-11.10:56:46 robot:Googlebot URL:Googlebot/2.1+(+http://www.google.com/bot.html)Time:2009-09-11.11:47:17 robot:Googlebot URL:Googlebot/2.1+(+http://www.google.com/bot.html)Time:2009-09-11.11:52:19 robot:Googlebot URL:Googlebot/2.1+(+http://www.google.com/bot.html)Time:2009-09-11.11:56:56 robot:Googlebot URL:Googlebot/2.1+(+http://www.google.com/bot.html)Time:2009-09-11.12:59:23 robot:Baiduspider URL:Baiduspider+(+http://www.baidu.com/search/spider.htm)Time:2009-09-11.14:28:18 robot:Baiduspider URL:Baiduspider+(+http://www.baidu.com/search/spider.htm)Time:2009-09-11.14:43:39 robot:Baiduspider URL:Baiduspider+(+http://www.baidu.com/search/spider.htm)
  • 相关文章:
  • 发表评论:
  • *
  • *
  • ◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

日历