PHPackages                             topoff/user-agent-parser - 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. topoff/user-agent-parser

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

topoff/user-agent-parser
========================

UserAgent parsing done right

v7.0.0(4mo ago)15.8kMITPHPPHP ^8.3

Since Nov 8Pushed 4mo ago2 watchersCompare

[ Source](https://github.com/topoff/user-agent-parser)[ Packagist](https://packagist.org/packages/topoff/user-agent-parser)[ RSS](/packages/topoff-user-agent-parser/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (6)Dependencies (14)Versions (35)Used By (0)

UserAgentParser
===============

[](#useragentparser)

[![Build Status](https://camo.githubusercontent.com/8de5bb52851ab143307492e1834a9de5ed32776172a539259dad93f92565bbf4/68747470733a2f2f7472617669732d63692e6f72672f546861446166696e7365722f557365724167656e745061727365722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/ThaDafinser/UserAgentParser)[![Code Coverage](https://camo.githubusercontent.com/47d7992e589f59c2ac4ea2eb63df7e8532bf29964a73273db0958a1dd8342f53/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f546861446166696e7365722f557365724167656e745061727365722f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/ThaDafinser/UserAgentParser/?branch=master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/1c8bd72e3fdbf144a6d1e1dc779f50369b6ec43d49c6e4ecdd34f0e20ee2edea/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f546861446166696e7365722f557365724167656e745061727365722f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/ThaDafinser/UserAgentParser/?branch=master)

[![Latest Stable Version](https://camo.githubusercontent.com/25b15427dcf75622cee5e57ec0085782da6645a46961fd7b89816261929ce94a/68747470733a2f2f706f7365722e707567782e6f72672f746861646166696e7365722f757365722d6167656e742d7061727365722f762f737461626c65)](https://packagist.org/packages/thadafinser/user-agent-parser)[![Latest Unstable Version](https://camo.githubusercontent.com/faa3f2995b7746b887808c5a95c90d649bcdc90204efbb5e1e4cd7170cd3e091/68747470733a2f2f706f7365722e707567782e6f72672f746861646166696e7365722f757365722d6167656e742d7061727365722f762f756e737461626c65)](https://packagist.org/packages/thadafinser/user-agent-parser)[![License](https://camo.githubusercontent.com/18dd0ae495801d8382eef1361138e229c9ca07de6b7050dc8a650e287394476f/68747470733a2f2f706f7365722e707567782e6f72672f746861646166696e7365722f757365722d6167656e742d7061727365722f6c6963656e7365)](https://packagist.org/packages/thadafinser/user-agent-parser)[![Total Downloads](https://camo.githubusercontent.com/3d6e0ffb047081697cf3453ee16781b8e6aa3970528b09b0954f51e5cc323faf/68747470733a2f2f706f7365722e707567782e6f72672f746861646166696e7365722f757365722d6167656e742d7061727365722f646f776e6c6f616473)](https://packagist.org/packages/thadafinser/user-agent-parser)

`User agent` parsing is, was and will always be a painful thing.

The target of this package is to make it less painful, by providing an abstract layer for many user agent parsers.

Currently **11 local providers** and **6 HTTP providers** are available! [See the comparison list here](https://github.com/ThaDafinser/UserAgentParser#providers)

So you can

- use multiple providers at the same time with the `Chain` provider
- use local and/or HTTP API providers at the same time
- switch between different parsers, without changing your code
- compare the result of the different parsers
- get always the same result model, regardless of which parser you use currently

The quality of this package is currently covered by

- ***unit tests*** (373 tests, 746 assertions)
- ***integration tests*** (86 tests, 310 assertions)
- ***regular real result testing*** (the results of ***over 33.000 user agents*** are compared [here](http://thadafinser.github.io/UserAgentParserComparison/))

Try it out
----------

[](#try-it-out)

[LIVE test](http://useragent.mkf.solutions/)

[Compare the detection results of the parsers](http://thadafinser.github.io/UserAgentParserComparison/)

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

[](#installation)

Using composer is currently the only supported way to install this package.

```
composer require thadafinser/user-agent-parser

```

`Note:` to use local providers you need to install additional packages, which are listed inside the composer `suggests section`

Getting started
---------------

[](#getting-started)

You need to register an API key or install an additional package (listed in the section `suggest` of `composer.json`)

```
use UserAgentParser\Exception\NoResultFoundException;
use UserAgentParser\Provider\WhichBrowser;

$provider = new WhichBrowser();

try {
    /* @var $result \UserAgentParser\Model\UserAgent */
    $result = $provider->parse('Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.73 Safari/537.36');
} catch (NoResultFoundException $ex){
    // nothing found
}

if($result->isBot() === true) {
  // if one part has no result, it's always set not null
  $result->getBot()->getName();
  $result->getBot()->getType();
} else {
  // if one part has no result, it's always set not null
  $result->getBrowser()->getName();
  $result->getBrowser()->getVersion()->getComplete();

  $result->getRenderingEngine()->getName();
  $result->getRenderingEngine()->getVersion()->getComplete();

  $result->getOperatingSystem()->getName();
  $result->getOperatingSystem()->getVersion()->getComplete();

  $result->getDevice()->getModel();
  $result->getDevice()->getBrand();
  $result->getDevice()->getType();
  $result->getDevice()->getIsMobile();
  $result->getDevice()->getIsTouch();
}
```

Use cases
---------

[](#use-cases)

### Bot or human

[](#bot-or-human)

```
// initialisation see Getting started
if($result->isBot() === true) {
    // do something special with the bot
}
```

### Mobile detection

[](#mobile-detection)

```
// initialisation see Getting started
if($result->isMobile() === true) {
    // redirect to the the mobile optimized page or suggest the other to download your app
    // NOTE mobile means not "phone". It can be any moveable device, e.g. tablet, media player, watch, ...
}
```

Providers
---------

[](#providers)

UserAgentParser comes with local and http providers

See detailed documenation here

[local providers](docs/01-local-providers.md)

[http providers](docs/02-http-providers.md)

NameTypeBrowserEngineOperating systemDevice modelDevice brandDevice typeIs mobileIs botBot nameBot typeCommentBrowscapFulllocalxxxxxxxxxxBrowscapLitelocalxxxxBrowscapPhplocalxxxxxxDonatjUAParserlocalxEndorphinlocalxxxxxxHandsetDetectionlocalxxxxJenssegersAgentlocalxxxxxBased on MobileDetectMatomoDeviceDetectorlocalxxxxxxxxxxSinergiBrowserDetectorlocalxxxxxUAParserlocalxxxxxxWhichBrowserlocalxxxxxxxxWootheelocalxxxxZsxsoftlocalxxxxDeviceAtlasComhttpxxxxfree availableFiftyOneDegreesComhttpxxxxxxxxfree unlimitedNeutrinoApiComhttpxxxxxxxx25/day freeUdgerComhttpxxxxx500/month free (API key only for one month valid!)UserAgentApiComhttpxxxxx1000/day freeWhatIsMyBrowserComhttpxx500/month free### Local providers

[](#local-providers)

Local providers are (most time) faster then HTTP providers and dont require a working internet connection. But you need to update them yourself from time to time, to make sure you detect the latest UAs

- BrowscapFull
- BrowscapLite
- BrowscapPhp
- DonatjUAParser
- Endorphin
- HandsetDetection
- JenssegersAgent
- MatomoDeviceDetector
- SinergiBrowserDetector
- UAParser
- WhichBrowser
- Woothee
- Zsxsoft

### HTTP providers (API)

[](#http-providers-api)

HTTP providers are simple to use, since you need only an API key to get started. But they require (always) a working internet connection.

- Http\\DeviceAtlasCom
- Http\\FiftyOneDegreesCom
- Http\\NeutrinoApiCom
- Http\\UdgerCom
- Http\\UserAgentApiCom
- Http\\WhatIsMyBrowserCom

### Comparison matrix

[](#comparison-matrix)

Here is a comparison matrix, with many analyzed UserAgent strings, to help you device which provider fits your needs. Every provider has it's strengh and weakness, so it will depend on your need, which one you should use.

[Go to the comparison](http://thadafinser.github.io/UserAgentParserComparison/)

### Overview

[](#overview)

### Single provider

[](#single-provider)

```
require 'vendor/autoload.php';

use UserAgentParser\Provider;

$userAgent = 'Mozilla/5.0 (iPod; U; CPU iPhone OS 4_3_5 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8J2 Safari/6533.18.5';

$provider = new Provider\MatomoDeviceDetector();

/* @var $result \UserAgentParser\Model\UserAgent */
$result = $provider->parse($userAgent);
// optional add all headers, to improve the result further
// $result = $provider->parse($userAgent, getallheaders());

$result->getBrowser()->getName(); // Mobile Safari
$result->getOperatingSystem()->getName(); // iOS
$result->getDevice()->getBrand(); // iPod Touch
$result->getDevice()->getBrand(); // Apple
$result->getDevice()->getType(); // portable media player

$resultArray = $result->toArray();
```

### Chain provider

[](#chain-provider)

This is very useful to improve your results. The chain provider starts with the first provider and checks if there is a result, if not it takes the next one and so on. If none of them have a result, it will throw a NoResultException like a single provider.

```
require 'vendor/autoload.php';

use UserAgentParser\Provider;

$userAgent = 'Mozilla/5.0 (iPod; U; CPU iPhone OS 4_3_5 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8J2 Safari/6533.18.5';

$chain = new Provider\Chain([
    new Provider\MatomoDeviceDetector(),
    new Provider\WhichBrowser(),
    new Provider\UAParser(),
    new Provider\Woothee(),
    new Provider\DonatjUAParser()
]);

/* @var $result \UserAgentParser\Model\UserAgent */
$result = $chain->parse($userAgent);
// optional add all headers, to improve the result further (used currently only by WhichBrowser)
//$result = $chain->parse($userAgent, getallheaders());

$result->getBrowser()->getName(); // Mobile Safari

$result->getOperatingSystem()->getName(); // iOS

$result->getDevice()->getBrand(); // iPod Touch
$result->getDevice()->getBrand(); // Apple
$result->getDevice()->getType(); // portable media player

$resultArray = $result->toArray();
```

###  Health Score

53

—

FairBetter than 96% of packages

Maintenance74

Regular maintenance activity

Popularity19

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity90

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 93.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 ~110 days

Recently: every ~476 days

Total

35

Last Release

139d ago

Major Versions

v2.0.1 → v3.0.02020-11-24

v3.0.0 → v4.0.02020-11-24

v4.1.0 → v5.0.02020-11-24

v5.0.1 → v6.0.02021-11-24

v5.1.0 → v7.0.02026-02-12

PHP version history (6 changes)v0.1.0PHP &gt;=5.6

v0.7.0PHP &gt;=5.5

v1.2.0PHP ~5.6|~7.0

v5.0.0PHP ~7.3

v6.0.0PHP ^7.4|^8.0

v5.1.0PHP ^8.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/f1546327b4f6a5440d3a984bf6e3bb771f70d61b244ad2f224f1638c570549b3?d=identicon)[topoff](/maintainers/topoff)

---

Top Contributors

[![ThaDafinser](https://avatars.githubusercontent.com/u/533017?v=4)](https://github.com/ThaDafinser "ThaDafinser (323 commits)")[![NielsLeenheer](https://avatars.githubusercontent.com/u/233230?v=4)](https://github.com/NielsLeenheer "NielsLeenheer (13 commits)")[![ndberg](https://avatars.githubusercontent.com/u/13345669?v=4)](https://github.com/ndberg "ndberg (8 commits)")[![Machou](https://avatars.githubusercontent.com/u/1043650?v=4)](https://github.com/Machou "Machou (1 commits)")[![photodude](https://avatars.githubusercontent.com/u/10253980?v=4)](https://github.com/photodude "photodude (1 commits)")[![topoff-old](https://avatars.githubusercontent.com/u/26787140?v=4)](https://github.com/topoff-old "topoff-old (1 commits)")

---

Tags

User agent parser

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Rector

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/topoff-user-agent-parser/health.svg)

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

###  Alternatives

[laravel/framework

The Laravel Framework.

34.8k543.8M19.7k](/packages/laravel-framework)[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

751291.4k40](/packages/civicrm-civicrm-core)[drupal/core

Drupal is an open source content management platform powering millions of websites and applications.

21866.0M1.7k](/packages/drupal-core)[typo3/cms

TYPO3 CMS is a free open source Content Management Framework initially created by Kasper Skaarhoj and licensed under GNU/GPL.

1.2k1.9M122](/packages/typo3-cms)[neuron-core/neuron-ai

The PHP Agentic Framework.

2.0k656.1k38](/packages/neuron-core-neuron-ai)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

585.6M559](/packages/shopware-core)

PHPackages © 2026

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