douweiluo0600
douweiluo0600
2012-02-05 16:22

PHP get_browser在WAMP和Linux服务器上返回不同的结果

已采纳

When using the get_browser function in PHP on:

  • Linux server - works perfectly.
  • WAMP server - returns "Default Browser"

I have just downloaded the latest browscap.in file.

My user_agent is: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:9.0.1) Gecko/20100101 Firefox/9.0.1

WAMP:

Array
(
    [browser_name_regex] => §^.*$§
    [browser_name_pattern] => *
    [browser] => Default Browser
    [version] => 0
    [majorver] => 0
    [minorver] => 0
    [platform] => unknown
    [alpha] => 
    [beta] => 
    [win16] => 
    [win32] => 
    [win64] => 
    [frames] => 
    [iframes] => 
    [tables] => 
    [cookies] => 
    [backgroundsounds] => 
    [javascript] => 
    [vbscript] => 
    [javaapplets] => 
    [activexcontrols] => 
    [isbanned] => 
    [ismobiledevice] => 
    [issyndicationreader] => 
    [crawler] => 
    [cssversion] => 0
    [aolversion] => 0
)

Server:

Array
(
    [browser_name_regex] => �^mozilla/5\.0 \(.*windows nt 6\.1.*wow64.*rv:.*\) gecko/.* firefox/9\..*$�
    [browser_name_pattern] => Mozilla/5.0 (*Windows NT 6.1*WOW64*rv:*) Gecko/* Firefox/9.*
    [parent] => Firefox 9.0
    [platform] => Win7
    [win32] => 
    [win64] => 1
    [browser] => Firefox
    [version] => 9.0
    [majorver] => 9
    [frames] => 1
    [iframes] => 1
    [tables] => 1
    [cookies] => 1
    [javascript] => 1
    [javaapplets] => 1
    [cssversion] => 3
    [minorver] => 0
    [alpha] => 
    [beta] => 
    [win16] => 
    [backgroundsounds] => 
    [vbscript] => 
    [activexcontrols] => 
    [isbanned] => 
    [ismobiledevice] => 
    [issyndicationreader] => 
    [crawler] => 
    [aolversion] => 0
)

QUESTION: How do I fix this issue in WAMP so that it behaviours like the linux server?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

2条回答

  • doudian7996 doudian7996 9年前

    I suggest to use this "Standalone replacement for php's native get_browser() function" https://github.com/garetjax/phpbrowscap

    This library is suggested to be used in the Browsercap page

    Here is a list of the features:

    • Fast
    • Standalone
    • Even faster parsing many user agents
    • Fully get_browser() compatible
    • Often faster and more accurate than get_browser()
    • Fully PHP configuration independent
    • User agent auto-detection
    • Returns object or array
    • Parsed .ini file cached directly into PHP arrays
    • Accepts any .ini file (even ASP and lite versions)
    • Auto updated browscap.ini file and cache from remote server with version checking
    • Configurable remote update server
    • Fully configurable (since 0.2)
    • PHP4 and PHP5 compatible (PHP4 version deprecated)
    • Released under the MIT License
    点赞 评论 复制链接分享
  • douyong6589 douyong6589 9年前

    Seems that your php.ini file didn't contain path to browscap ini file.

    Look if there present this setting:

    [browscap]
    browscap = /path/to/your/php_browscap.ini
    
    点赞 评论 复制链接分享