请问如何用PHP代码来判断搜索引擎蜘蛛来路,作出判断后执行其它代码。比如:被判断出是百度蜘蛛来访问时,网页执行一种代码,正常用户访问或者其它引擎蜘蛛来访问时,网页执行另一种代码。麻烦高手赐教,偶是PHP新手,最好能得到详细一些,如实例代码的答案,谢谢! 

解决方案 »

  1.   

    <?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;
    }
    ?>
      

  2.   

    根据$_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)
    ……你是不是想以这种方式,加入无关关键词,搜索作弊?可能会被惩罚的,慎用
      

  3.   

    主要使用user_agent来判断的,有网站收录了很多的user_agent用作匹配
    http://user-agent-string.info/download/UASparser-for-PHP
      

  4.   

    搜索作弊!  沒有必要 完全可以SEO 來搞定排名
      

  5.   

    崇明农家乐旅游http://www.chongmingu8.com
      

  6.   

    谢谢大家帮忙,已经结贴,请接分哦!还想请大家帮我一下,有关MYSQL子查询的问题,打开以下地址:
    http://topic.csdn.net/u/20100720/22/6049d9a2-ea75-4f57-a5a7-507e781dfb2f.html?45731