zoukankan      html  css  js  c++  java
  • 检测浏览网站的是否是蜘蛛

    实现流程是: 

      1、判断用户端的浏览器类型

      2、根据搜索引擎机器人的名称进行判断用户是否蜘蛛人

    /**
     * 判断是否为搜索引擎蜘蛛
     *
     * @access  public
     * @return  string
     */
    function is_spider($record = true)
    {
        static $spider = NULL;
    
        if ($spider !== NULL)
        {
            return $spider;
        }
    
        if (empty($_SERVER['HTTP_USER_AGENT']))
        {
            $spider = '';
    
            return '';
        }
    
        $searchengine_bot = array(
            'googlebot',
            'mediapartners-google',
            'baiduspider+',
            'msnbot',
            'yodaobot',
            'yahoo! slurp;',
            'yahoo! slurp china;',
            'iaskspider',
            'sogou web spider',
            'sogou push spider'
        );
    
        $searchengine_name = array(
            'GOOGLE',
            'GOOGLE ADSENSE',
            'BAIDU',
            'MSN',
            'YODAO',
            'YAHOO',
            'Yahoo China',
            'IASK',
            'SOGOU',
            'SOGOU'
        );
    
        $spider = strtolower($_SERVER['HTTP_USER_AGENT']);
    
        foreach ($searchengine_bot AS $key => $value)
        {
            if (strpos($spider, $value) !== false)
            {
                $spider = $searchengine_name[$key];
    
                /*if ($record === true)
                {
                    $GLOBALS['db']->autoReplace($GLOBALS['ecs']->table('searchengine'), array('date' => local_date('Y-m-d'), 'searchengine' => $spider, 'count' => 1), array('count' => 1));
                }*/
    
                return $spider;
            }
        }
    
        $spider = '';
    
        return '';
    }
  • 相关阅读:
    Linux Shell 用法
    gdb调试用法
    grep 用法总结
    Cmake用法
    Win64/Linux 上PyMouse安装
    两道拓扑排序的问题
    hiho一下第76周《Suzhou Adventure》
    这类问题需要利用二进制的特殊性
    这种题应该诸位处理
    两道人数多,课程少,query多的题
  • 原文地址:https://www.cnblogs.com/zjfazc/p/2708798.html
Copyright © 2011-2022 走看看