Browser detection with PHP

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

  1. 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.
  2. Save it somewhere sensible on the server – I put it in /usr/lib64/php/extras/browscap.ini on our 64-bit server.
  3. Edit php.ini, and add the following line section (or edit it if it’s already there) :
    [browscap]
    browscap = /usr/lib64/php/extras/browscap.ini
  4. Now restart apache
    $ sudo apachectl restart
  1. Now if you use the get_browser() function, it should return something like the following :
    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
    ) 


No Responses to “Browser detection with PHP”  

Leave a Reply