PHPackages                             ornicar/php-user-agent - 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. ornicar/php-user-agent

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

ornicar/php-user-agent
======================

1.0.0(12y ago)148305.9k—8.9%30[3 PRs](https://github.com/ornicar/php-user-agent/pulls)MITPHPPHP &gt;=5.3.0

Since Jul 9Pushed 8y ago10 watchersCompare

[ Source](https://github.com/ornicar/php-user-agent)[ Packagist](https://packagist.org/packages/ornicar/php-user-agent)[ RSS](/packages/ornicar-php-user-agent/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (2)Used By (0)

PHP User Agent
==============

[](#php-user-agent)

Browser detection in PHP5. Uses a simple and fast algorithm to recognize major browsers.

Overview
--------

[](#overview)

```
$userAgent = new phpUserAgent();

$userAgent->getBrowserName()      // firefox
$userAgent->getBrowserVersion()   // 3.6
$userAgent->getOperatingSystem()  // linux
$userAgent->getEngine()           // gecko
```

### Why you should use it

[](#why-you-should-use-it)

PHP provides a native function to detect user browser: [get\_browser()](http://us2.php.net/manual/en/function.get-browser.php). get\_browser() requires the "browscap.ini" file which is 300KB+. Loading and processing this file impact script performance. And sometimes, the production server just doesn't provide browscap.ini.

Although get\_browser() surely provides excellent detection results, in most cases a much simpler method can be just as effective. php-user-agent has the advantage of being compact and easy to extend. It is performant as well, since it doesn't do any iteration or recursion.

Usage
-----

[](#usage)

```
// include classes or rely on Composer autoloader
require_once '/path/to/php-user-agent/phpUserAgent.php';
require_once '/path/to/php-user-agent/phpUserAgentStringParser.php';

// Create a user agent
$userAgent = new phpUserAgent();

// Interrogate the user agent
$userAgent->getBrowserName()      // firefox
$userAgent->getBrowserVersion()   // 3.6
$userAgent->getOperatingSystem()  // linux
$userAgent->getEngine()           // gecko
```

Advanced
--------

[](#advanced)

### Custom user agent string

[](#custom-user-agent-string)

When you create a phpUserAgent object, the current user agent string is used. You can specify another user agent string:

```
// use another user agent string
$userAgent = new phpUserAgent('msnbot/2.0b (+http://search.msn.com/msnbot.htm)');
$userAgent->getBrowserName() // msnbot

// use current user agent string
$userAgent = new phpUserAgent($_SERVER['HTTP_USER_AGENT');
// this is equivalent to:
$userAgent = new phpUserAgent();
```

### Custom parser class

[](#custom-parser-class)

By default, phpUserAgentStringParser is used to analyse the user agent string. You can replace the parser instance and customize it to match your needs:

```
// create a custom user agent string parser
class myUserAgentStringParser extends phpUserAgentStringParser
{
  // override methods
}

// inject the custom parser when creating a user agent:
$userAgent = new phpUserAgent(null, new myUserAgentStringParser());
```

Run tests
---------

[](#run-tests)

You can run the unit tests on your server:

```
$ php prove.php
```

Contribute
----------

[](#contribute)

If you found a browser of operating system this library fails to recognize, feel free to submit an issue. Please provide the user agent string. And well, if you also want to provide the patch, it's even better.

###  Health Score

41

—

FairBetter than 89% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity51

Moderate usage in the ecosystem

Community20

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 63.3% 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

Unknown

Total

1

Last Release

4696d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/808f1df1f6ccd749b9c985f3b4a8753788e9bf74e7cead639fcf49cd2a714fd0?d=identicon)[egeloen](/maintainers/egeloen)

---

Top Contributors

[![ornicar](https://avatars.githubusercontent.com/u/140370?v=4)](https://github.com/ornicar "ornicar (19 commits)")[![GeLoLabs](https://avatars.githubusercontent.com/u/149005863?v=4)](https://github.com/GeLoLabs "GeLoLabs (5 commits)")[![dkushnikov](https://avatars.githubusercontent.com/u/1129911?v=4)](https://github.com/dkushnikov "dkushnikov (4 commits)")[![cystbear](https://avatars.githubusercontent.com/u/412004?v=4)](https://github.com/cystbear "cystbear (2 commits)")

---

Tags

user agent

### Embed Badge

![Health badge](/badges/ornicar-php-user-agent/health.svg)

```
[![Health](https://phpackages.com/badges/ornicar-php-user-agent/health.svg)](https://phpackages.com/packages/ornicar-php-user-agent)
```

###  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)[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.

5876.7M19](/packages/cbschuld-browserphp)[jaybizzle/laravel-crawler-detect

A Laravel package to detect web crawlers via the user agent

3232.6M17](/packages/jaybizzle-laravel-crawler-detect)[garetjax/phpbrowscap

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

437862.4k5](/packages/garetjax-phpbrowscap)[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)

PHPackages © 2026

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