请问如何用PHP代码来判断搜索引擎蜘蛛来路?

白眉2009 2010-07-16 09:50:54
请问如何用PHP代码来判断搜索引擎蜘蛛来路,作出判断后执行其它代码。

比如:被判断出是百度蜘蛛来访问时,网页执行一种代码,正常用户访问或者其它引擎蜘蛛来访问时,网页执行另一种代码。

麻烦高手赐教,偶是PHP新手,最好能得到详细一些,如实例代码的答案,谢谢!
...全文
306 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
白眉2009 2010-07-20
  • 打赏
  • 举报
回复
谢谢大家帮忙,已经结贴,请接分哦!还想请大家帮我一下,有关MYSQL子查询的问题,打开以下地址:
http://topic.csdn.net/u/20100720/22/6049d9a2-ea75-4f57-a5a7-507e781dfb2f.html?45731
jianglin28290 2010-07-16
  • 打赏
  • 举报
回复
主要使用user_agent来判断的,有网站收录了很多的user_agent用作匹配
http://user-agent-string.info/download/UASparser-for-PHP
amani11 2010-07-16
  • 打赏
  • 举报
回复
根据$_SERVER['HTTP_REFERER']判断来路

根据$_SERVER['HTTP_USER_AGENT']来识别访问者身份

比如
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322, Baidu-Transcoder/1.0.6.0, gate.baidu.com)

msnbot/1.1 (+http://search.msn.com/msnbot.htm)

Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)
……

你是不是想以这种方式,加入无关关键词,搜索作弊?可能会被惩罚的,慎用
CunningBoy 2010-07-16
  • 打赏
  • 举报
回复
<?php
function get_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;
}
?>
dehong 2010-07-16
  • 打赏
  • 举报
回复
乱打广告,小心封你的号。
blackgsb 2010-07-16
  • 打赏
  • 举报
回复
崇明农家乐旅游http://www.chongmingu8.com
liuyang1588 2010-07-16
  • 打赏
  • 举报
回复
搜索作弊! 沒有必要 完全可以SEO 來搞定排名

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧