建议先判断爬虫,再判断浏览器类型。现在国内主流的两个爬虫,百度、360的UA均有Mozilla字符串,如果先判断浏览器类型,那么可能会误判。

百度UA【Mozilla/5.0 (compatible; Baiduspider/2.0; +http://www.baidu.com/search/spider.html)】
360UA【Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.8.0.11)  Firefox/1.5.0.11; 360Spider】
这个问题在网站日志中发现,由于使用了IS_ROBOT常量判断,导致360误判严重。
This commit is contained in:
test_discuz 2017-09-10 02:36:46 +08:00
parent f81bea6175
commit b430fc0e89
1 changed files with 1 additions and 1 deletions

View File

@ -310,8 +310,8 @@ function checkrobot($useragent = '') {
static $kw_browsers = array('msie', 'netscape', 'opera', 'konqueror', 'mozilla');
$useragent = strtolower(empty($useragent) ? $_SERVER['HTTP_USER_AGENT'] : $useragent);
if(strpos($useragent, 'http://') === false && dstrpos($useragent, $kw_browsers)) return false;
if(dstrpos($useragent, $kw_spiders)) return true;
if(strpos($useragent, 'http://') === false && dstrpos($useragent, $kw_browsers)) return false;
return false;
}
function checkmobile() {