×

php

判断是否为搜索引擎蜘蛛

天外来信 天外来信 发表于2012-07-07 01:21:32 浏览3022 评论0

抢沙发发表评论

  1. /**  
  2.  * 判断是否为搜索引擎蜘蛛  
  3.  *  
  4.  * @access  public  
  5.  * @return  string  
  6.  */  
  7. function is_spider($record = true)  
  8. {  
  9.     static $spider = NULL;  
  10.   
  11.     if ($spider !== NULL)  
  12.     {  
  13.         return $spider;  
  14.     }  
  15.   
  16.     if (empty($_SERVER['HTTP_USER_AGENT']))  
  17.     {  
  18.         $spider = '';  
  19.   
  20.         return '';  
  21.     }  
  22.   
  23.     $searchengine_bot = array(  
  24.         'googlebot',  
  25.         'mediapartners-google',  
  26.         'baiduspider+',  
  27.         'msnbot',  
  28.         'yodaobot',  
  29.         'yahoo! slurp;',  
  30.         'yahoo! slurp china;',  
  31.         'iaskspider',  
  32.         'sogou web spider',  
  33.         'sogou push spider'  
  34.     );  
  35.   
  36.     $searchengine_name = array(  
  37.         'GOOGLE',  
  38.         'GOOGLE ADSENSE',  
  39.         'BAIDU',  
  40.         'MSN',  
  41.         'YODAO',  
  42.         'YAHOO',  
  43.         'Yahoo China',  
  44.         'IASK',  
  45.         'SOGOU',  
  46.         'SOGOU'  
  47.     );  
  48.   
  49.     $spider = strtolower($_SERVER['HTTP_USER_AGENT']);  
  50.   
  51.     foreach ($searchengine_bot AS $key => $value)  
  52.     {  
  53.         if (strpos($spider, $value) !== false)  
  54.         {  
  55.             $spider = $searchengine_name[$key];  
  56.   
  57.             if ($record === true)  
  58.             {  
  59.                 $GLOBALS['db']->autoReplace($GLOBALS['ecs']->table('searchengine'), array('date' => local_date('Y-m-d'), 'searchengine' => $spider, 'count' => 1), array('count' => 1));  
  60.             }  
  61.   
  62.             return $spider;  
  63.         }  
  64.     }  
  65.   
  66.     $spider = '';  
  67.   
  68.     return '';  
  69. }  

评论列表

访客