The easiest way is to use the PHP get_browser function, as this will parse the HTTP HTTP user header and extract the appropriate browser, versions, platforms, etc. to an array or object as needed.
Running this (in array mode for the purposes of this example) will return the data structure in the following format (using the current php_browscap.ini file from Browser Capability Project dated January 15, 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 )
NB: According to the PHP manual page:
"For this to work, the cast configuration in php.ini must point to the correct location of the browsercap.ini file on your system."
source share