PHPackages                             bugbuster/browscap-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. bugbuster/browscap-php

ActiveLibrary

bugbuster/browscap-php
======================

Standalone replacement for php's native get\_browser() function

7.4.0(2y ago)02.7k↓20.5%1MITPHPPHP ~8.1.0 || ~8.2.0 || ~8.3.0

Since Jul 22Pushed 3mo agoCompare

[ Source](https://github.com/BugBuster1701/browscap-php)[ Packagist](https://packagist.org/packages/bugbuster/browscap-php)[ Docs](https://github.com/browscap/browscap-php)[ RSS](/packages/bugbuster-browscap-php/feed)WikiDiscussions bugbuster Synced 1mo ago

READMEChangelogDependencies (16)Versions (51)Used By (0)

Browser Capabilities PHP Project (FORK)
=======================================

[](#browser-capabilities-php-project-fork)

This is a userland replacement for PHP's native `get_browser()` function, which is *officially supported* by the Browser Capabilities Project.

[![Latest Stable Fork Version](https://camo.githubusercontent.com/f2bf7a98c00f1942beb24a704b9a71881abaa28e3cb4b1023f160b094edeeaf6/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f737461626c652d372e322e332d626c75652e737667)](https://packagist.org/packages/bugbuster/browscap-php#7.2.3)

Fork: Special version for Contao 5.3 and PHP 8.3/8.4 with Monolog 2.9, used by the Contao BotDetection Bundle. Pure elimination of dependency conflicts, Contao BotDetection Bundle uses `NullLogger()`.

Installation
------------

[](#installation)

Run the command below to install via Composer

```
composer require bugbuster/browscap-php
```

Then you may identify the current user agent this way:

```
$cache = new \MatthiasMullie\Scrapbook\Psr16\SimpleCache($doctrineFileCache); // or maybe any other PSR-16 compatible caches
$logger = new \Monolog\Logger('name'); // or maybe any other PSR-3 compatible logger

$browscap = new \BrowscapPHP\Browscap($cache, $logger);
$info = $browscap->getBrowser();
```

Recommended Setup
-----------------

[](#recommended-setup)

Before you can start, you have to run the `browscap:fetch` command to download the `browscap.ini` file, and use the `browscap:convert` command to convert it into a cache. There are two ways.

a. Download the file and convert it in two steps. The downloaded file will be stored in a local file, but there is no check if the remote file has changed. If your cache gets corrupted you only need to rerun the `convert` command.

```
vendor/bin/browscap-php browscap:fetch
vendor/bin/browscap-php browscap:convert
```

b. Download the file and convert it in one step. The downloaded file will not be stored in a local file, but there is a check if the remote file has changed. If your cache gets corrupted you have clean the cache and restart the process.

```
vendor/bin/browscap-php browscap:update
```

If you want to autoupdate the used cache, we recommend a separate cron job that calls the command listed above.

BC breaks in version 7.0.x
--------------------------

[](#bc-breaks-in-version-70x)

```
 - [BC] BrowscapPHP\Command\UpdateCommand was marked "@internal"
 - [BC] BrowscapPHP\Command\FetchCommand was marked "@internal"
 - [BC] BrowscapPHP\Command\ConvertCommand was marked "@internal"
 - [BC] BrowscapPHP\Command\CheckUpdateCommand was marked "@internal"
 - [BC] BrowscapPHP\Command\ParserCommand was marked "@internal"
 - [BC] BrowscapPHP\Helper\Filesystem was marked "@internal"

```

Setup Examples
--------------

[](#setup-examples)

```
$fileCache = new \League\Flysystem\Local\LocalFilesystemAdapter($cacheDir);
$filesystem = new \League\Flysystem\Filesystem($fileCache);
$cache = new \MatthiasMullie\Scrapbook\Psr16\SimpleCache(
    new \MatthiasMullie\Scrapbook\Adapters\Flysystem($filesystem)
);

$logger = new \Monolog\Logger('name');

$bc = new \BrowscapPHP\Browscap($cache, $logger);
$result = $bc->getBrowser();
```

NOTE: You may use any other cache which implements the [PSR-16](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-16-simple-cache.md) interface.

Using the full browscap.ini file
--------------------------------

[](#using-the-full-browscapini-file)

```
$bc = new \BrowscapPHP\BrowscapUpdater();
$bc->update(\BrowscapPHP\Helper\IniLoaderInterface::PHP_INI_FULL);
```

Setting up a proxy configuration
--------------------------------

[](#setting-up-a-proxy-configuration)

If you are behind a proxy or need a spcific configuration, you have to set up a client instance. See into the [Guzzle documentation](http://docs.guzzlephp.org/en/latest/) for more information about this.

```
$proxyConfig = [
    'proxy' => [
        'http'  => 'tcp://localhost:8125',
        'https' => 'tcp://localhost:8124',
    ],
];
$client = new \GuzzleHttp\Client($proxyConfig);
$bcu = new BrowscapUpdater();
$bcu->setClient($client);
```

Usage Examples
--------------

[](#usage-examples)

Taking the user agent from the global $\_SERVER variable
--------------------------------------------------------

[](#taking-the-user-agent-from-the-global-_server-variable)

```
$bc = new \BrowscapPHP\Browscap();
$current_browser = $bc->getBrowser();
```

Using a sample useragent
------------------------

[](#using-a-sample-useragent)

```
$bc = new \BrowscapPHP\Browscap($cache, $logger);
$current_browser = $bc->getBrowser($the_user_agent);
```

the CLI commands
----------------

[](#the-cli-commands)

NOTE: If you don't want to use a file cache, you could not use the CLI commands. It is not possible to use other caches there at the moment. NOTE: Each operation (fetch, update, check-update) which fetches data from the remote host browscap.org may run into the rate limit of that site. If this happens an Exception is thrown.

Each CLI command returns `zero` if everything went fine.

check-update
------------

[](#check-update)

If you only want to check if a new version of the browscap.ini is available, you can use the `check-update` command.

```
vendor/bin/browscap-php browscap:check-update
```

### options

[](#options)

- `cache` (optional) the relative path to your cache directory

### return codes

[](#return-codes)

- 1: no cached version found
- 2: no new version availble
- 3: an error occured while checking the cached version
- 4: an error occured while fetching the remote version
- 5: an other error occured

fetch
-----

[](#fetch)

The `fetch` command downloads an ini file from browscap.org.

```
vendor/bin/browscap-php browscap:fetch
```

### options

[](#options-1)

- `cache` (optional) the relative path to your cache directory
- `remote-file` (optional) only required if you dont want to download the standerd file, possible values are
    - `PHP_BrowscapINI` downloads the standard file (default)
    - `Lite_PHP_BrowscapINI` downloads the lite file
    - `Full_PHP_BrowscapINI` downloads the full file
- `file` (optional) the relative path to the local file where the remote content is stored

### return codes

[](#return-codes-1)

- 3: an error occured while checking the cached version
- 9: an error occured while fetching the remote data
- 10: an other error occured

convert
-------

[](#convert)

The `convert` command reads a local stored browscap.ini file and writes the contents into a cache.

```
vendor/bin/browscap-php browscap:convert
```

### options

[](#options-2)

- `file` (optional) the relative path to the local file where the remote content is stored, this should be the same file as in the fetch command
- `cache` (optional) the relative path to your cache directory

### return codes

[](#return-codes-2)

- 6: the name of the file to convert is missing
- 7: the file to convert is not available or not readable
- 8: an other error occured while reading the file

update
------

[](#update)

The `update` command downloads an ini file from browscap.org and writes the contents into a cache. No local files are created.

```
vendor/bin/browscap-php browscap:update
```

### options

[](#options-3)

- `remote-file`(optional) only required if you dont want to download the standerd file, possible values are
    - `PHP_BrowscapINI` downloads the standard file (default)
    - `Lite_PHP_BrowscapINI` downloads the lite file
    - `Full_PHP_BrowscapINI` downloads the full file
- `cache` (optional) the relative path to your cache directory

### return codes

[](#return-codes-3)

- 3: an error occured while checking the cached version
- 9: an error occured while fetching the remote data
- 10: an other error occured

parse
-----

[](#parse)

The `parse` command parses a given user agent and writes the result to the console.

```
vendor/bin/browscap-php browscap:parse
```

### options

[](#options-4)

- `user-agent` (required) the user agent which should be parsed
- `cache` (optional) the relative path to your cache directory

### return codes

[](#return-codes-4)

- 11: an other error occured while parsing the useragent

CLI Examples
------------

[](#cli-examples)

Updating the cache using the full browscap.ini file
---------------------------------------------------

[](#updating-the-cache-using-the-full-browscapini-file)

Note: Both ways to create/update the cache will use the `standard` mode file as default. If you want more detailed information you may change this with the `remote-file` option. Please use the help function this parameter.

```
vendor/bin/browscap-php browscap:update --remote-file Full_PHP_BrowscapINI
```

Updating a custom cache dir
---------------------------

[](#updating-a-custom-cache-dir)

Each operation expect fetch uses a cache inside the `resources` directory inside the project. If you update this library with composer, the cache is cleared also. If you want to avoid this and want to set your own cache folder, you can use the `cache` option. If you do this, you have to set a Cache Instance for this this path.

```
vendor/bin/browscap-php browscap:update --cache ./browscap-cache
```

Issues and feature requests
---------------------------

[](#issues-and-feature-requests)

Please report your issues and ask for new features on the GitHub Issue Tracker at

Please report incorrectly identified User Agents and browser detect in the browscap.ini file here:

###  Health Score

51

—

FairBetter than 96% of packages

Maintenance55

Moderate activity, may be stable

Popularity23

Limited adoption so far

Community20

Small or concentrated contributor base

Maturity91

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 50.1% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~105 days

Recently: every ~176 days

Total

48

Last Release

94d ago

Major Versions

2.1.1 → 3.0.0-rc.12016-02-16

3.1.0 → 4.0.02017-12-29

4.3.x-dev → 5.0.02021-01-06

5.1.x-dev → 6.0.02021-12-11

6.2.x-dev → 7.0.02022-02-23

PHP version history (15 changes)1.0.0PHP &gt;=5.3.0

3.0.0-alpha.1PHP &gt;=5.5.0

3.0.0PHP ^5.6|^7.0

3.1.0PHP ^5.6 || ^7.0

4.0.0PHP ~7.1.0

4.1.0PHP &gt;=7.1.0,&lt;7.3.0

4.2.0PHP &gt;=7.1.0,&lt;7.4.0

4.2.2PHP &gt;=7.1.0,&lt;7.5.0

5.0.0PHP &gt;=7.3.0,&lt;8.1.0

6.0.0PHP &gt;=7.4.3,&lt;8.2.0

7.2.0PHP &gt;=7.4.3,&lt;8.3.0

7.3.0PHP ~8.1.0 || ~8.2.0 || ~8.3.0

7.2.1PHP &gt;=8.1.0,&lt;8.4.0

7.2.3PHP &gt;=8.1.0,&lt;8.5.0

7.2.4PHP ^8.3

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/497111?v=4)[Anton Safonov](/maintainers/BugBuster)[@BugBuster](https://github.com/BugBuster)

---

Top Contributors

[![mimmi20](https://avatars.githubusercontent.com/u/1120192?v=4)](https://github.com/mimmi20 "mimmi20 (542 commits)")[![asgrim](https://avatars.githubusercontent.com/u/496145?v=4)](https://github.com/asgrim "asgrim (284 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (111 commits)")[![dependabot-preview[bot]](https://avatars.githubusercontent.com/in/2141?v=4)](https://github.com/dependabot-preview[bot] "dependabot-preview[bot] (22 commits)")[![GaretJax](https://avatars.githubusercontent.com/u/86236?v=4)](https://github.com/GaretJax "GaretJax (20 commits)")[![scrutinizer-auto-fixer](https://avatars.githubusercontent.com/u/6253494?v=4)](https://github.com/scrutinizer-auto-fixer "scrutinizer-auto-fixer (13 commits)")[![jaydiablo](https://avatars.githubusercontent.com/u/136907?v=4)](https://github.com/jaydiablo "jaydiablo (11 commits)")[![quentin389](https://avatars.githubusercontent.com/u/2136749?v=4)](https://github.com/quentin389 "quentin389 (9 commits)")[![Slamdunk](https://avatars.githubusercontent.com/u/152236?v=4)](https://github.com/Slamdunk "Slamdunk (8 commits)")[![BugBuster1701](https://avatars.githubusercontent.com/u/1218809?v=4)](https://github.com/BugBuster1701 "BugBuster1701 (6 commits)")[![DaAwesomeP](https://avatars.githubusercontent.com/u/4472083?v=4)](https://github.com/DaAwesomeP "DaAwesomeP (5 commits)")[![DominikTo](https://avatars.githubusercontent.com/u/1384635?v=4)](https://github.com/DominikTo "DominikTo (5 commits)")[![duxthefux](https://avatars.githubusercontent.com/u/6758162?v=4)](https://github.com/duxthefux "duxthefux (4 commits)")[![ThaDafinser](https://avatars.githubusercontent.com/u/533017?v=4)](https://github.com/ThaDafinser "ThaDafinser (4 commits)")[![tmolitor-stud-tu](https://avatars.githubusercontent.com/u/6234248?v=4)](https://github.com/tmolitor-stud-tu "tmolitor-stud-tu (4 commits)")[![vitorbrandao](https://avatars.githubusercontent.com/u/109226?v=4)](https://github.com/vitorbrandao "vitorbrandao (4 commits)")[![holtkamp](https://avatars.githubusercontent.com/u/776405?v=4)](https://github.com/holtkamp "holtkamp (4 commits)")[![onyxg](https://avatars.githubusercontent.com/u/12340537?v=4)](https://github.com/onyxg "onyxg (3 commits)")[![jonathaningram](https://avatars.githubusercontent.com/u/626664?v=4)](https://github.com/jonathaningram "jonathaningram (3 commits)")[![cihantas](https://avatars.githubusercontent.com/u/1579976?v=4)](https://github.com/cihantas "cihantas (3 commits)")

---

Tags

browseruser agentget\_browsercapabilities

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/bugbuster-browscap-php/health.svg)

```
[![Health](https://phpackages.com/badges/bugbuster-browscap-php/health.svg)](https://phpackages.com/packages/bugbuster-browscap-php)
```

###  Alternatives

[laravel/framework

The Laravel Framework.

34.7k509.9M17.0k](/packages/laravel-framework)[browscap/browscap-php

Standalone replacement for php's native get\_browser() function

4413.8M22](/packages/browscap-browscap-php)[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

595.2M386](/packages/shopware-core)[magento/community-edition

Magento 2 (Open Source)

12.1k52.1k10](/packages/magento-community-edition)[ec-cube/ec-cube

EC-CUBE EC open platform.

78527.0k1](/packages/ec-cube-ec-cube)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
