browscap and get_browser in PHP

If you want to know the capabilities of the current users browser in PHP you can use the get_browser() function.

mixed get_browser ([ string $user_agent [, bool $return_array = false ]] )

But first you have to configure the browscap option in php.ini with a browscap.ini file containing browsers information.

get_browser error

You can download different browscap.ini file versions from http://browscap.org/, copy it along with php.ini and then configure the browscap option with the ABSOLUTE path to it:

[browscap]
; http://php.net/browscap
browscap = /opt/local/etc/php5/full_php_browscap.ini

Once the web server is restarted verify it’s configured with php_info():

php_info-browscap

And then you may call get_browser(), for example with this:

$browser = get_browser();
var_dump($browser);

You’ll get something like this:

object(stdClass)[1]
  public 'browser_name_regex' => string '§^mozilla/5.0 (.*mac os x 10_9.*) applewebkit/.* (khtml, like gecko).*chrome/36..*safari/.*$§' (length=99)
  public 'browser_name_pattern' => string 'Mozilla/5.0 (*Mac OS X 10_9*) AppleWebKit/* (KHTML, like Gecko)*Chrome/36.*Safari/*' (length=83)
  public 'parent' => string 'Chrome 36.0' (length=11)
  public 'browser_bits' => string '32' (length=2)
  public 'platform' => string 'MacOSX' (length=6)
  public 'platform_version' => string '10.9' (length=4)
  public 'platform_description' => string 'Mac OS X' (length=8)
  public 'platform_bits' => string '32' (length=2)
  public 'platform_maker' => string 'Apple Inc' (length=9)
  public 'win32' => string '' (length=0)
  public 'device_name' => string 'Macintosh' (length=9)
  public 'device_maker' => string 'Apple Inc' (length=9)
  public 'device_code_name' => string 'Macintosh' (length=9)
  public 'device_brand_name' => string 'Apple' (length=5)
  public 'comment' => string 'Chrome 36.0' (length=11)
  public 'browser' => string 'Chrome' (length=6)
  public 'browser_type' => string 'Browser' (length=7)
  public 'browser_maker' => string 'Google Inc' (length=10)
  public 'version' => string '36.0' (length=4)
  public 'majorver' => string '36' (length=2)
  public 'frames' => string '1' (length=1)
  public 'iframes' => string '1' (length=1)
  public 'tables' => string '1' (length=1)
  public 'cookies' => string '1' (length=1)
  public 'javascript' => string '1' (length=1)
  public 'javaapplets' => string '1' (length=1)
  public 'cssversion' => string '3' (length=1)
  public 'device_type' => string 'Desktop' (length=7)
  public 'device_pointing_method' => string 'mouse' (length=5)
  public 'renderingengine_name' => string 'Blink' (length=5)
  public 'renderingengine_description' => string 'a WebKit Fork by Google' (length=23)
  public 'renderingengine_maker' => string 'Google Inc' (length=10)
  public 'browser_modus' => string 'unknown' (length=7)
  public 'minorver' => string '0' (length=1)
  public 'alpha' => string '' (length=0)
  public 'beta' => string '' (length=0)
  public 'win16' => string '' (length=0)
  public 'win64' => string '' (length=0)
  public 'backgroundsounds' => string '' (length=0)
  public 'vbscript' => string '' (length=0)
  public 'activexcontrols' => string '' (length=0)
  public 'ismobiledevice' => string '' (length=0)
  public 'istablet' => string '' (length=0)
  public 'issyndicationreader' => string '' (length=0)
  public 'crawler' => string '' (length=0)
  public 'aolversion' => string '0' (length=1)
  public 'renderingengine_version' => string 'unknown' (length=7)

Ref: http://php.net/manual/en/function.get-browser.php
http://php.net/manual/en/misc.configuration.php#ini.browscap

You might also like

How to install Google Chrome in Ubuntu
First add the signing key and the repository:wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub...

Using MacPorts php from command line
Some time ago I had installed Apache+MySQL using MacPorts in Mac OS X. It was all OK as long as I used...

Install a Symfony2 application using Composer
Before installing any Symfony2 project you have to meet the minimum requirements for it in your server....

Can’t change user options in MySQL Administrator
May be you installed MySQL 5 and you are not able to change user information, schema privileges and resources...

  1. I downloaded the full_php_browscap.ini and included in the file path in /etc/php5/apache2/php.ini file
    . My script still keeps complaining about browscap directive not being set. Can you help me?

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.