how to detect internet explorer and firefox using PHP?

前端 未结 6 687
傲寒
傲寒 2021-01-29 09:05

how to detect internet explorer and firefox using PHP?

6条回答
  •  再見小時候
    2021-01-29 09:14

    The easiest way is to use PHP's get_browser function, as this will parse the HTTP User-Agent header for you and extract the relevant browser, version, platform, etc. information into an array or object as required.

    Running this (in array mode for the purposes of this example) will return a data structure in the following format (using the current php_browscap.ini file from the Browser Capabilities Project as of 15th Jan 2011):

    Array
    (
        [browser_name_regex] => �^mozilla/5\.0 \(windows; u; windows nt 6\.1; .*\) applewebkit/.* \(khtml, like gecko\) chrome/8\..* safari/.*$�
        [browser_name_pattern] => Mozilla/5.0 (Windows; U; Windows NT 6.1; *) AppleWebKit/* (KHTML, like Gecko) Chrome/8.* Safari/*
        [parent] => Chrome 8.0
        [browser] => Chrome
        [platform] => Win7
        [version] => 8.0
        [majorver] => 8
        [win32] => 1
        [frames] => 1
        [iframes] => 1
        [tables] => 1
        [cookies] => 1
        [javaapplets] => 1
        [javascript] => 1
        [cssversion] => 3
        [supportscss] => 1
        [minorver] => 0
        [alpha] => 
        [beta] => 
        [win16] => 
        [win64] => 
        [backgroundsounds] => 
        [cdf] => 
        [vbscript] => 
        [activexcontrols] => 
        [isbanned] => 
        [ismobiledevice] => 
        [issyndicationreader] => 
        [crawler] => 
        [aol] => 
        [aolversion] => 0
    )
    

    N.B.: As per the PHP manual page:

    "In order for this to work, your browscap configuration setting in php.ini must point to the correct location of the browscap.ini file on your system."

提交回复
热议问题