联系官方销售客服

1835022288

028-61286886

开发框架 版主:迅睿框架研发组
怎么在模板中判断是否是蜘蛛访问,如果是蜘蛛访问就展现其他的内容,不是的就正常内容
类型:迅睿CMS 更新时间:2022-02-09 14:26:54

模板标签里面

怎么在模板中判断是否是蜘蛛访问,如果是蜘蛛访问就展现其他的内容,不是的就正常内容。 有判断代码吗?

回帖
  • 迅睿框架联合创始人
    #1楼    迅睿框架联合创始人
    2021-12-28 11:09:53
    Chrome 0
    这个可以去百度搜索一个判断蜘蛛的php函数,然后在模板里面判断这个函数就行了
  • 仿站织梦转换特199
    #2楼    仿站织梦转换特199
    2021-12-28 11:11:58
    Chrome 0
    function is_spider(){
    $robot = 0;
    $USER_AGENT = strtolower($_SERVER['HTTP_USER_AGENT']);
    if(strpos($USER_AGENT,"bot")) $robot = 1;
    if(strpos($USER_AGENT,"spider")) $robot = 1;
    if(strpos($USER_AGENT,"slurp")) $robot = 1;
    if(strpos($USER_AGENT,"mediapartners-google")) $robot = 1;
    if(strpos($USER_AGENT,"fast-webcrawler")) $robot = 1;
    if(strpos($USER_AGENT,"altavista")) $robot = 1;
    if(strpos($USER_AGENT,"ia_archiver")) $robot = 1;
    if($robot == 1){
    //do something
    }
    return '';
    }
    满意答案
  • 仿站织梦转换特199
    #3楼    仿站织梦转换特199
    2021-12-28 11:21:37
    Chrome 0
    function isCrawler() {
        echo $agent= strtolower($_SERVER['HTTP_USER_AGENT']);
        if (!empty($agent)) {
            $spiderSite= array(
                "TencentTraveler",
                "Baiduspider+",
                "BaiduGame",
                "Googlebot",
                "msnbot",
                "Sosospider+",
                "Sogou web spider",
                "ia_archiver",
                "Yahoo! Slurp",
                "YoudaoBot",
                "Yahoo Slurp",
                "MSNBot",
                "Java (Often spam bot)",
                "BaiDuSpider",
                "Voila",
                "Yandex bot",
                "BSpider",
                "twiceler",
                "Sogou Spider",
                "Speedy Spider",
                "Google AdSense",
                "Heritrix",
                "Python-urllib",
                "Alexa (IA Archiver)",
                "Ask",
                "Exabot",
                "Custo",
                "OutfoxBot/YodaoBot",
                "yacy",
                "SurveyBot",
                "legs",
                "lwp-trivial",
                "Nutch",
                "StackRambler",
                "The web archive (IA Archiver)",
                "Perl tool",
                "MJ12bot",
                "Netcraft",
                "MSIECrawler",
                "WGet tools",
                "larbin",
                "Fish search",
            );
            foreach($spiderSite as $val) {
                $str = strtolower($val);
                if (strpos($agent, $str) !== false) {
                    return true;
                }
            }
        } else {
            return false;
        }
    }
    if (isCrawler()){
        echo "你好蜘蛛精!";
    }
    else{
       echo "你不是蜘蛛精啊!";
    }


  • 一休哥
    #4楼    一休哥
    2021-12-28 11:26:54
    Chrome 0
    收藏一下,以后可能用得上
  • 影子
    #5楼    影子
    2021-12-28 11:31:49
    Chrome 0
    二楼的函数可以,我一直在使用,只是有点瑕疵
  • 仿站织梦转换特199
    #6楼    仿站织梦转换特199
    2022-02-09 14:26:54
    Chrome 0
    @仿站织梦转换特199:我自己测试了,可用