This project is now hosted on google code at the following URL: http://code.google.com/p/phpbrowscap/.

This page is going to be removed as far as the whole content is ported to the new platform, please refer to the new URL for future reference.

Introduction

The browscap.ini file is a database maintained by Gary Keith at http://browsers.garykeith.com/ which provides a lot of details about browsers and their capabilities, such as name, versions, JavaScript support and so on.

PHP's native get_browser() function parses this file and provides you with a complete set of information about every browser's details. But it requires the path to the browscap.ini file to be specified in the php.ini browscap directive which is flagged as PHP_INI_SYSTEM. That means in most shared hosting environments you cannot edit the php.ini file.

Browscap is a standalone class for both PHP4 and PHP5 that gets around the limitations of get_browser() and manages the whole thing. It offers methods to update, cache, adapt and get details about every supplied user agent on a standalone basis.

Download

Download the latest release of the Browscap class:

Features

Here is a feature list of the Browscap class:

Quick Start

How to quickly setup your browser capabilities script without get_browser():

  1. Download the package and unpack it
  2. Upload everything on your server (You haven't to modify the Browscap class!)
  3. Change permissions on Browscap/cache to 666 (you might need 777)
  4. Create a .php file with the following content:
    
    <?php

    // Loads the class
    require 'path/to/Browscap.php';

    // Creates a new Browscap object (loads or creates the cache)
    $bc = new Browscap('path/to/the/cache/dir');

    // Gets information about the current browser's user agent
    $current_browser = $bc->getBrowser();

    // Output the result
    echo '<pre>'; // some formatting issues ;)
    print_r($current_browser);
    echo '</pre>';
  5. Open your web browser and navigate to the file you just created
  6. You should see a result similar to the example with your browser's information

Example

This is the information about the browser you're currently using as returned by the Browscap class:

stdClass Object
(
    [browser_name] => CCBot/1.0 (+http://www.commoncrawl.org/bot.html)
    [browser_name_regex] => ^.*$
    [browser_name_pattern] => *
    [Browser] => Default Browser
    [Version] => 0
    [MajorVer] => 0
    [MinorVer] => 0
    [Platform] => unknown
    [Alpha] => 
    [Beta] => 
    [Win16] => 
    [Win32] => 
    [Win64] => 
    [Frames] => 1
    [IFrames] => 
    [Tables] => 1
    [Cookies] => 
    [BackgroundSounds] => 
    [AuthenticodeUpdate] => 0
    [CDF] => 
    [VBScript] => 
    [JavaApplets] => 
    [JavaScript] => 
    [ActiveXControls] => 
    [Stripper] => 
    [isBanned] => 
    [WAP] => 
    [isMobileDevice] => 
    [isSyndicationReader] => 
    [Crawler] => 
    [CSS] => 0
    [CssVersion] => 0
    [supportsCSS] => 
    [AOL] => 
    [aolVersion] => 0
    [netCLR] => 
    [ClrVersion] => 0
)

Changelog

License & Credits

The whole work is released under the GNU Lesser General Public License (Take a look at the license).

The browscap.ini database is released under Gary Keith's Terms of Use.

Special thanks goes to Gary Keith for the big job he does maintaining the Browser Capabilities project and offering such great support, as well as to Alexandre Alapetite for pointing me in the right direction and to the guys from ba!joodoo for the first implementation of an interval based update version.

Contact

Because your opinion matters.

If only to say "Hello, it works!", or to ask for a feature or report a bug, or for basic support write to:

Also via instant messenger:

You can also register to the forums and ask there for help.