PHPackages                             cbschuld/browser.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. [Utility &amp; Helpers](/categories/utility)
4. /
5. cbschuld/browser.php

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

cbschuld/browser.php
====================

A PHP Class to detect a user's Browser. This encapsulation provides a breakdown of the browser and the version of the browser using the browser's user-agent string. This is not a guaranteed solution but provides an overall accurate way to detect what browser a user is using.

v2.0.0(8mo ago)5876.7M—3.2%294[12 issues](https://github.com/cbschuld/Browser.php/issues)[2 PRs](https://github.com/cbschuld/Browser.php/pulls)16MITPHPPHP &gt;=8.0CI passing

Since Jun 26Pushed 8mo ago61 watchersCompare

[ Source](https://github.com/cbschuld/Browser.php)[ Packagist](https://packagist.org/packages/cbschuld/browser.php)[ Docs](https://chrisschuld.com/projects/browser-php-detecting-a-users-browser-from-php/)[ RSS](/packages/cbschuld-browserphp/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (7)Dependencies (1)Versions (8)Used By (16)

cbschuld/browser.php
====================

[](#cbschuldbrowserphp)

[![Tests](https://github.com/cbschuld/Browser.php/actions/workflows/tests.yml/badge.svg)](https://github.com/cbschuld/Browser.php/actions/workflows/tests.yml)

Helps detect the user's browser and platform at the PHP level via the user agent

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

[](#installation)

### Via Composer (Recommended)

[](#via-composer-recommended)

```
composer require cbschuld/browser.php
```

For development only:

```
composer require --dev cbschuld/browser.php
```

### Direct Download

[](#direct-download)

Download `Browser.php` and include it in your project:

```
require_once 'Browser.php';
```

Usage
-----

[](#usage)

### Modern Usage (v2.0+, Recommended)

[](#modern-usage-v20-recommended)

```
use cbschuld\Browser;

$browser = new Browser();
if ($browser->getBrowser() == Browser::BROWSER_FIREFOX && $browser->compareVersion('10', '>=')) {
    echo 'You have Firefox version 10 or greater';
}
```

### Legacy Usage (Still Supported)

[](#legacy-usage-still-supported)

```
// Works via automatic aliasing - no namespace needed
$browser = new Browser();
if ($browser->getBrowser() == Browser::BROWSER_FIREFOX && $browser->getVersion() >= 10) {
    echo 'You have Firefox version 10 or greater';
}
```

### Version Comparison (PHP 8+ Compatible)

[](#version-comparison-php-8-compatible)

```
use cbschuld\Browser;

$browser = new Browser();

// Recommended approach for version comparison
if ($browser->compareVersion('15.0', '>=')) {
    echo 'Modern browser detected';
}

// Multiple comparisons
if ($browser->getBrowser() == Browser::BROWSER_CHROME &&
    $browser->compareVersion('90', '>=')) {
    echo 'Modern Chrome detected';
}
```

Browser Detection
-----------------

[](#browser-detection)

This solution identifies the following Browsers and does a best-guess on the version:

- Opera (`Browser::BROWSER_OPERA`)
- WebTV (`Browser::BROWSER_WEBTV`)
- NetPositive (`Browser::BROWSER_NETPOSITIVE`)
- Edge (`Browser::BROWSER_EDGE`)
- Internet Explorer (`Browser::BROWSER_IE`)
- Pocket Internet Explorer (`Browser::BROWSER_POCKET_IE`)
- Galeon (`Browser::BROWSER_GALEON`)
- Konqueror (`Browser::BROWSER_KONQUEROR`)
- iCab (`Browser::BROWSER_ICAB`)
- OmniWeb (`Browser::BROWSER_OMNIWEB`)
- Phoenix (`Browser::BROWSER_PHOENIX`)
- Firebird (`Browser::BROWSER_FIREBIRD`)
- UCBrowser (`Browser::BROWSER_UCBROWSER`)
- Firefox (`Browser::BROWSER_FIREFOX`)
- Mozilla (`Browser::BROWSER_MOZILLA`)
- Palemoon (`Browser::BROWSER_PALEMOON`)
- curl (`Browser::BROWSER_CURL`)
- wget (`Browser::BROWSER_WGET`)
- Amaya (`Browser::BROWSER_AMAYA`)
- Lynx (`Browser::BROWSER_LYNX`)
- Safari (`Browser::BROWSER_SAFARI`)
- Playstation (`Browser::BROWSER_PLAYSTATION`)
- iPhone (`Browser::BROWSER_IPHONE`)
- iPod (`Browser::BROWSER_IPOD`)
- Google's Android(`Browser::BROWSER_ANDROID`)
- Google's Chrome(`Browser::BROWSER_CHROME`)
- GoogleBot(`Browser::BROWSER_GOOGLEBOT`)
- Yahoo!'s Slurp(`Browser::BROWSER_SLURP`)
- W3C's Validator(`Browser::BROWSER_W3CVALIDATOR`)
- BlackBerry(`Browser::BROWSER_BLACKBERRY`)

Operating System Detection
--------------------------

[](#operating-system-detection)

This solution identifies the following Operating Systems:

- Windows (`Browser::PLATFORM_WINDOWS`)
- Windows CE (`Browser::PLATFORM_WINDOWS_CE`)
- Apple (`Browser::PLATFORM_APPLE`)
- Linux (`Browser::PLATFORM_LINUX`)
- Android (`Browser::PLATFORM_ANDROID`)
- OS/2 (`Browser::PLATFORM_OS2`)
- BeOS (`Browser::PLATFORM_BEOS`)
- iPhone (`Browser::PLATFORM_IPHONE`)
- iPod (`Browser::PLATFORM_IPOD`)
- BlackBerry (`Browser::PLATFORM_BLACKBERRY`)
- FreeBSD (`Browser::PLATFORM_FREEBSD`)
- OpenBSD (`Browser::PLATFORM_OPENBSD`)
- NetBSD (`Browser::PLATFORM_NETBSD`)
- SunOS (`Browser::PLATFORM_SUNOS`)
- OpenSolaris (`Browser::PLATFORM_OPENSOLARIS`)
- iPad (`Browser::PLATFORM_IPAD`)

History and Legacy
------------------

[](#history-and-legacy)

Detecting the user's browser type and version is helpful in web applications that harness some of the newer bleeding edge concepts. With the browser type and version you can notify users about challenges they may experience and suggest they upgrade before using such application. Not a great idea on a large scale public site; but on a private application this type of check can be helpful.

In an active project of mine we have a pretty graphically intensive and visually appealing user interface which leverages a lot of transparent PNG files. Because we all know how great IE6 supports PNG files it was necessary for us to tell our users the lack of power their browser has in a kind way.

Searching for a way to do this at the PHP layer and not at the client layer was more of a challenge than I would have guessed; the only script available was written by Gary White and Gary no longer maintains this script because of reliability. I do agree 100% with Gary about the readability; however, there are realistic reasons to desire the user's browser and browser version and if your visitor is not echoing a false user agent we can take an educated guess.

I based this solution off of Gary White's original work but have since replaced all of his original code. Either way, thank you to Gary. Sadly, I never was able to get in touch with him regarding this solution.

Testing
-------

[](#testing)

The testing with PHPUnit against known user agents available in tests/lists. Each file is tab delimited with the following fields:

User Agent, User Agent Type, Browser, Version, Operating System, Operating System Version

eg

```
Opera/9.80 (X11; Linux i686; Ubuntu/14.10) Presto/2.12.388 Version/12.16	Browser	Opera	12.16	Linux	Linux
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_2) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.186 Safari/535.1   Browser	Chrome	14.0.835.186	Macintosh	OS X		10_7_2

```

Tests can be run by phpunit:

```
vendor/bin/phpunit
```

Upgrading from v1.x
-------------------

[](#upgrading-from-v1x)

See [UPGRADING.md](UPGRADING.md) for detailed migration instructions.

**Quick Summary:**

- v2.0 requires PHP 8.0+
- Class is now namespaced: `cbschuld\Browser`
- Backward compatibility maintained via automatic aliasing
- Use `compareVersion()` for reliable version comparisons

###  Health Score

63

—

FairBetter than 99% of packages

Maintenance60

Regular maintenance activity

Popularity68

Solid adoption and visibility

Community43

Growing community involvement

Maturity69

Established project with proven stability

 Bus Factor1

Top contributor holds 72% 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 ~377 days

Recently: every ~562 days

Total

7

Last Release

256d ago

Major Versions

v1.9.6 → v2.0.02025-09-04

PHP version history (2 changes)1.9.2PHP &gt;=7.2

v2.0.0PHP &gt;=8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/231867?v=4)[Chris Schuld](/maintainers/cbschuld)[@cbschuld](https://github.com/cbschuld)

---

Top Contributors

[![cbschuld](https://avatars.githubusercontent.com/u/231867?v=4)](https://github.com/cbschuld "cbschuld (85 commits)")[![Marco129](https://avatars.githubusercontent.com/u/4252133?v=4)](https://github.com/Marco129 "Marco129 (8 commits)")[![Rigiytip](https://avatars.githubusercontent.com/u/2422544?v=4)](https://github.com/Rigiytip "Rigiytip (3 commits)")[![bburnichon](https://avatars.githubusercontent.com/u/2437286?v=4)](https://github.com/bburnichon "bburnichon (3 commits)")[![mavrick](https://avatars.githubusercontent.com/u/357659?v=4)](https://github.com/mavrick "mavrick (2 commits)")[![adaxi](https://avatars.githubusercontent.com/u/474682?v=4)](https://github.com/adaxi "adaxi (2 commits)")[![stiko](https://avatars.githubusercontent.com/u/8698522?v=4)](https://github.com/stiko "stiko (2 commits)")[![GramThanos](https://avatars.githubusercontent.com/u/14858959?v=4)](https://github.com/GramThanos "GramThanos (2 commits)")[![Otamay](https://avatars.githubusercontent.com/u/905688?v=4)](https://github.com/Otamay "Otamay (2 commits)")[![romainneutron](https://avatars.githubusercontent.com/u/137574?v=4)](https://github.com/romainneutron "romainneutron (2 commits)")[![trejjam](https://avatars.githubusercontent.com/u/3594540?v=4)](https://github.com/trejjam "trejjam (1 commits)")[![baasha](https://avatars.githubusercontent.com/u/636120?v=4)](https://github.com/baasha "baasha (1 commits)")[![davidus-sk](https://avatars.githubusercontent.com/u/10680124?v=4)](https://github.com/davidus-sk "davidus-sk (1 commits)")[![FootballFan141](https://avatars.githubusercontent.com/u/6156499?v=4)](https://github.com/FootballFan141 "FootballFan141 (1 commits)")[![igaponov](https://avatars.githubusercontent.com/u/4271889?v=4)](https://github.com/igaponov "igaponov (1 commits)")[![jasonlam604](https://avatars.githubusercontent.com/u/1707104?v=4)](https://github.com/jasonlam604 "jasonlam604 (1 commits)")[![misilot](https://avatars.githubusercontent.com/u/1446856?v=4)](https://github.com/misilot "misilot (1 commits)")

---

Tags

browserphpuser-agentuseragentbrowseruser agentdetection

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/cbschuld-browserphp/health.svg)

```
[![Health](https://phpackages.com/badges/cbschuld-browserphp/health.svg)](https://phpackages.com/packages/cbschuld-browserphp)
```

###  Alternatives

[jenssegers/agent

Desktop/mobile user agent parser with support for Laravel, based on Mobiledetect

4.8k67.8M440](/packages/jenssegers-agent)[hisorange/browser-detect

Browser &amp; Mobile detection package for Laravel.

1.1k10.1M50](/packages/hisorange-browser-detect)[foroco/php-browser-detection

Ultra fast PHP library to detect browser, OS, platform and device type by User-Agent parsing

1554.7M7](/packages/foroco-php-browser-detection)[garetjax/phpbrowscap

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

437862.4k5](/packages/garetjax-phpbrowscap)[wolfcast/browser-detection

The Wolfcast BrowserDetection PHP class facilitates the identification of the user's environment such as Web browser, version, platform family, platform version or if it's a mobile device or not.

1391.0M7](/packages/wolfcast-browser-detection)[propa/laravel-browscap

Browscap-PHP integration for Laravel 5-12

1060.3k](/packages/propa-laravel-browscap)

PHPackages © 2026

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