PHPackages                             donatj/phpuseragentparser - 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. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. donatj/phpuseragentparser

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

donatj/phpuseragentparser
=========================

Lightning fast, minimalist PHP UserAgent string parser.

v1.11.0(9mo ago)59517.5M↓34.6%127[9 issues](https://github.com/donatj/PhpUserAgent/issues)[2 PRs](https://github.com/donatj/PhpUserAgent/pulls)20MITPHPPHP &gt;=5.4.0CI passing

Since Jul 24Pushed 1mo ago31 watchersCompare

[ Source](https://github.com/donatj/PhpUserAgent)[ Packagist](https://packagist.org/packages/donatj/phpuseragentparser)[ Docs](https://donatstudios.com/PHP-Parser-HTTP_USER_AGENT)[ Fund](https://www.paypal.me/donatj/15)[ GitHub Sponsors](https://github.com/donatj)[ RSS](/packages/donatj-phpuseragentparser/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (10)Dependencies (3)Versions (63)Used By (20)

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

[](#php-user-agent-parser)

[![Join the chat at https://gitter.im/PhpUserAgentParser/Lobby](https://camo.githubusercontent.com/369e6ce035631d50f63e4648bbd67aaa40bb997eacd462abc426f9ad599083e9/68747470733a2f2f6261646765732e6769747465722e696d2f506870557365724167656e745061727365722f4c6f6262792e737667)](https://gitter.im/PhpUserAgentParser/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

[![Latest Stable Version](https://camo.githubusercontent.com/6b998a081c37cb737c21dd8ff45b74b024e6fe6f53dbc766a286b85d3b4551eb/68747470733a2f2f706f7365722e707567782e6f72672f646f6e61746a2f706870757365726167656e747061727365722f76657273696f6e)](https://packagist.org/packages/donatj/phpuseragentparser)[![Total Downloads](https://camo.githubusercontent.com/4c8ab6ead9dfda743a9ec064e3bf9cd0d769f05a45aee6b547f126daf4270df2/68747470733a2f2f706f7365722e707567782e6f72672f646f6e61746a2f706870757365726167656e747061727365722f646f776e6c6f616473)](https://packagist.org/packages/donatj/phpuseragentparser)[![License](https://camo.githubusercontent.com/7facd92bb38fef3835fb5a9da69eeb54cf70472ffa3c3b78877aeced5462719f/68747470733a2f2f706f7365722e707567782e6f72672f646f6e61746a2f706870757365726167656e747061727365722f6c6963656e7365)](https://packagist.org/packages/donatj/phpuseragentparser)[![ci.yml](https://github.com/donatj/phpUserAgent/actions/workflows/ci.yml/badge.svg)](https://github.com/donatj/phpUserAgent/actions/workflows/ci.yml)

What It Is
----------

[](#what-it-is)

A simple, streamlined PHP user-agent parser!

Licensed under the MIT license:

Upgrading to `1.*`
------------------

[](#upgrading-to-1)

The new `1.*` release **does not break compatibility** with `0.*` and nothing need to change to upgrade. However, the global `parse_user_agent` is now deprecated; it has been replaced with the namespaced `\donatj\UserAgent\parse_user_agent` and functions exactly the same. You can easily replace any existing call to `parse_user_agent` with `\donatj\UserAgent\parse_user_agent`

In addition, 1.x adds a convenience object wrapper you may use should you prefer. More information on this is in the Usage section below.

Why Use This
------------

[](#why-use-this)

You have your choice in user-agent parsers. This one detects **all modern browsers** in a very light, quick, understandable fashion. It is less than 200 lines of code, and consists of just three regular expressions! It can also correctly identify exotic versions of IE others fail on.

It offers 100% unit test coverage, is installable via Composer, and is very easy to use.

What It Does Not Do
-------------------

[](#what-it-does-not-do)

This is not meant as a browser "knowledge engine" but rather a simple parser. Anything not adequately provided directly by the user agent string itself will simply not be provided by this.

### OS Versions

[](#os-versions)

User-agent strings **are not** a reliable source of OS Version!

- Many agents simply don't send the information.
- Others provide varying levels of accuracy.
- Parsing Windows versions alone almost nearly doubles the size of the code.

I'm much more interested in keeping this thing *tiny* and accurate than adding niché features and would rather focus on things that can be **done well**.

All that said, there is the start of a [branch to do it](https://github.com/donatj/PhpUserAgent/tree/os_version_detection) I created for a client if you want to poke it, I update it from time to time, but frankly if you need to *reliably detect OS Version*, using user-agent isn't the way to do it. I'd go with JavaScript.

### Undetectable Browsers

[](#undetectable-browsers)

- **Brave** - Brave is simply not differentiable from Chrome. This was a design decision on their part.

### Undetectable Platforms

[](#undetectable-platforms)

- **iPadOS 13+** - Starting with iPadOS 13 and further hardened in 14, iPadOS returns the **exact** same string as macOS. It is no longer distinguishable by UA string. (See: [\#69](https://github.com/donatj/PhpUserAgent/issues/69))

Requirements
------------

[](#requirements)

- **php**: &gt;=5.4.0
- **ext-ctype**: \*

Installing
----------

[](#installing)

PHP User Agent is available through Packagist via Composer.

Install the latest version with:

```
composer require 'donatj/phpuseragentparser'
```

Usage
-----

[](#usage)

The classic procedural use is as simple as:

```
