Last updated 24 September 2015. Created on 28 April 2015.
Edited by AohRveTPV, peterx. Log in to edit this page.

Browscap,, provides an improved version of PHP's get_browser() function and can be used in your code or through several modules.

The Themekey theme switching module is one example of a module using Browscap through the Browscap API.


Read about the PHP get_browser() function at

Browscap adds browscap_get_browser() to perform the same function and return more information.

The only downside is a database table lookup. Use browscap_get_browser() once per new visitor, cache the required results in the visitor's session, and reuse browscap_get_browser() only if the visitor's user agent string changes.

browscap_get_browser() defaults to using $_SERVER['HTTP_USER_AGENT'] for the user agent string.

You can supply a different user agent string to browscap_get_browser() as follows.
browscap_get_browser('Mozilla/5.0 (Windows NT 6.1; WOW64; rv:37.0) Gecko/20100101 Firefox/37.0')

The PHP get_browser() function can return an object or an array. browscap_get_browser() always returns an array.

The following table shows the information returned from Mozilla/5.0 (Windows NT 6.1; WOW64; rv:37.0) Gecko/20100101 Firefox/37.0.

Header Content
comment Firefox 37.0
browser Firefox
browser_maker Mozilla Foundation
version 37.0
majorver 37
minorver 0
platform Win7
win32 false
win64 true
ismobiledevice false
istablet false
device_type Desktop
device_pointing_method mouse
parent Firefox 37.0
useragent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:37.0) Gecko/20100101 Firefox/37.0
browser_name_pattern Mozilla/5.0 (*Windows NT 6.1*WOW64*) Gecko* Firefox/37.0*


The following text is the Browscap README.txt file.

Browscap provides an improved version of PHP's get_browser() function.

The get_browser() function can be used to tell what a visitor's browser is
capable of. Unfortunately, the version provided by PHP has a number of
limitations, namely:

* It can be difficult or impossible to configure for shared hosting
* The data used to identify browsers and determine their capabilities requires
  consistent maintenance to keep up-to-date.

Browscap automates maintenance by storing browser data in a database and
automatically retrieving the latest data on a configurable schedule.


Browscap requires that your server be able to "phone out" (make a http request)
to retrieve and update its user agent database.

Note: Some hosting companies have this capability blocked.


If you are using MySQL, it is recommended to use InnoDB and not MyISAM as the
table storage engine. (InnoDB is the default for Drupal 7.) MyISAM does not
support transactions, and without transactions Browscap may not return correct
browser information while new Browscap data is being loaded.


Browscap can be installed via the standard Drupal installation process.


Modules can make use of browscap data by calling browscap_get_browser()
anywhere they would otherwise call the PHP get_browser()
( function.

Note: browser_name_regex is not returned.

Drush integration

To import the data via drush, use `drush browscap-import`.


Development of Browscap is sponsored by Acquia ( and the
Ontario Ministry of Northern Development and Mines (

A special thanks goes out to Gary Keith ( who provides
regular updates to the browscap user agent database, and specifically for
adding a non-zipped CSV version of browscap to support this module.

Looking for support? Visit the forums, or join #drupal-support in IRC.