Dave Perrett

Browser Detection With PHP

linux, osx, php, programming, web

You can use PHP’s get_browser() function to find out information about user’s browsers, but it takes a little setting up.

  • Download a browscap file from garykeith.com . I found lite_php_browscap.ini good enough for my needs, but depending on what you want you might want a different version.
  • Save it somewhere sensible on the server - I put it in /usr/lib64/php/extras/browscap.ini on our 64-bit server.
  • Edit php.ini, and add the following line section (or edit it if it’s already there) :“` bash [browscap] browscap = /usr/lib64/php/extras/browscap.ini
1
2
* Now restart apache``` bash
$ sudo apachectl restart
  • Now if you use the get_browser() function, it should return something like the following :php stdClass Object ( [browser_name_regex] => ^mozilla/5\.0 (macintosh; .; .*mac os x.*; .*rv:1\.9.*) gecko/.*$ [browser_name_pattern] => Mozilla/5.0 (Macintosh; ?; *Mac OS X*; *rv:1.9*) Gecko/* [parent] => Mozilla 1.9 [platform] => MacOSX [browser] => Mozilla [version] => 1.9 [majorver] => 1 [minorver] => 9 [alpha] => 1 [frames] => 1 [iframes] => 1 [tables] => 1 [cookies] => 1 [javaapplets] => 1 [javascript] => 1 [css] => 2 [cssversion] => 2 [supportscss] => 1 [beta] => [win16] => [win32] => [win64] => [backgroundsounds] => [authenticodeupdate] => [cdf] => [vbscript] => [activexcontrols] => [stripper] => [isbanned] => [wap] => [ismobiledevice] => [issyndicationreader] => [crawler] => [aol] => [aolversion] => 0 [netclr] => [clrversion] => 0 )