2017 © Pedro Peláez
 

library user-agent-parser

UserAgent parsing done right http://useragent.mkf.solutions/

image

thadafinser/user-agent-parser

UserAgent parsing done right http://useragent.mkf.solutions/

  • Tuesday, May 23, 2017
  • by ThaDafinser
  • Repository
  • 20 Watchers
  • 168 Stars
  • 63,052 Installations
  • PHP
  • 3 Dependents
  • 0 Suggesters
  • 29 Forks
  • 13 Open issues
  • 30 Versions
  • 14 % Grown

The README.md

UserAgentParser

Build Status Code Coverage Scrutinizer Code Quality, (*1)

Latest Stable Version Latest Unstable Version License Total Downloads, (*2)

User agent parsing is, was and will always be a painful thing., (*3)

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

Currently 11 local providers and 6 HTTP providers are available! See the comparison list here, (*5)

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, (*6)

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), (*7)

Try it out

LIVE test, (*8)

Compare the detection results of the parsers, (*9)

Installation

Using composer is currently the only supported way to install this package., (*10)

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, (*11)

Getting started

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

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

Bot or human

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

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

UserAgentParser comes with local and http providers, (*13)

See detailed documenation here, (*14)

local providers, (*15)

http providers, (*16)

Name Type Browser Engine Operating system Device model Device brand Device type Is mobile Is bot Bot name Bot type Comment
BrowscapFull local x x x x x x x x x x
BrowscapLite local x x x x
BrowscapPhp local x x x x x x
DonatjUAParser local x
Endorphin local x x x x x x
HandsetDetection local x x x x
JenssegersAgent local x x x x x Based on MobileDetect
PiwikDeviceDetector local x x x x x x x x x x
SinergiBrowserDetector local x x x x x
UAParser local x x x x x x
WhichBrowser local x x x x x x x x
Woothee local x x x x
Zsxsoft local x x x x
DeviceAtlasCom http x x x x free available
FiftyOneDegreesCom http x x x x x x x x free unlimited
NeutrinoApiCom http x x x x x x x x 25/day free
UdgerCom http x x x x x 500/month free (API key only for one month valid!)
UserAgentApiCom http x x x x x 1000/day free
WhatIsMyBrowserCom http x x 500/month free

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, (*17)

  • BrowscapFull
  • BrowscapLite
  • BrowscapPhp
  • DonatjUAParser
  • Endorphin
  • HandsetDetection
  • JenssegersAgent
  • PiwikDeviceDetector
  • SinergiBrowserDetector
  • UAParser
  • WhichBrowser
  • Woothee
  • Zsxsoft

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., (*18)

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

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., (*19)

Go to the comparison, (*20)

Overview

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\PiwikDeviceDetector();

/* @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

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., (*21)

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\PiwikDeviceDetector(),
    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();

The Versions

23/05 2017

dev-master

9999999-dev

UserAgent parsing done right http://useragent.mkf.solutions/

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar ThaDafinser

parser engine wurfl browser piwik user agent mobile detector useragent device os detection operating system mobile detection ua uaparser browscap get_browser device detection sniffing ua-parser jenssegers sinergi useragentparser rendering engine bot detection whichbrowser woothee ua parser user agent parser user agent detection mobile device detection donatj deviceatlas neutrinoapicom udgercom useragentapicom useragentstringcom whatismybrowsercom

11/05 2017

dev-feature/mimmi20

dev-feature/mimmi20

UserAgent parsing done right http://useragent.mkf.solutions/

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar ThaDafinser

parser engine wurfl browser piwik user agent mobile detector useragent device os detection operating system mobile detection ua uaparser browscap get_browser device detection sniffing ua-parser jenssegers sinergi useragentparser rendering engine bot detection whichbrowser woothee ua parser user agent parser user agent detection mobile device detection donatj deviceatlas neutrinoapicom udgercom useragentapicom useragentstringcom whatismybrowsercom

16/02 2017

v2.0.0

2.0.0.0

UserAgent parsing done right http://useragent.mkf.solutions/

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar ThaDafinser

parser engine wurfl browser piwik user agent mobile detector useragent device os detection operating system mobile detection ua uaparser browscap get_browser device detection sniffing ua-parser jenssegers sinergi useragentparser rendering engine bot detection whichbrowser woothee ua parser user agent parser user agent detection mobile device detection donatj deviceatlas neutrinoapicom udgercom useragentapicom useragentstringcom whatismybrowsercom

21/12 2016

dev-feature/whatismy

dev-feature/whatismy

UserAgentParser abstraction for different parse providers

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar ThaDafinser

parser engine wurfl browser piwik user agent mobile detector useragent device os detection operating system mobile detection ua uaparser browscap get_browser device detection sniffing ua-parser jenssegers sinergi useragentparser rendering engine bot detection whichbrowser woothee ua parser user agent parser user agent detection mobile device detection donatj deviceatlas neutrinoapicom udgercom useragentapicom useragentstringcom whatismybrowsercom

12/08 2016

v1.5.0

1.5.0.0

UserAgentParser abstraction for different parse providers

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar ThaDafinser

parser engine wurfl browser piwik user agent mobile detector useragent device os detection operating system mobile detection ua uaparser browscap get_browser device detection sniffing ua-parser jenssegers sinergi useragentparser rendering engine bot detection whichbrowser woothee ua parser user agent parser user agent detection mobile device detection donatj deviceatlas neutrinoapicom udgercom useragentapicom useragentstringcom whatismybrowsercom

13/07 2016

v1.4.0

1.4.0.0

UserAgentParser abstraction for different parse providers

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar ThaDafinser

parser engine wurfl browser piwik user agent mobile detector useragent device os detection operating system mobile detection ua uaparser browscap get_browser device detection sniffing ua-parser jenssegers sinergi useragentparser rendering engine bot detection whichbrowser woothee ua parser user agent parser user agent detection mobile device detection donatj deviceatlas neutrinoapicom udgercom useragentapicom useragentstringcom whatismybrowsercom

02/06 2016

dev-feature/detectright

dev-feature/detectright

UserAgentParser abstraction for different parse providers

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar ThaDafinser

parser engine wurfl browser piwik user agent mobile detector useragent device os detection operating system mobile detection ua uaparser browscap get_browser device detection sniffing ua-parser jenssegers sinergi useragentparser rendering engine bot detection whichbrowser woothee ua parser user agent parser user agent detection mobile device detection donatj deviceatlas neutrinoapicom udgercom useragentapicom useragentstringcom whatismybrowsercom

26/04 2016

v1.3.0

1.3.0.0

UserAgentParser abstraction for different parse providers

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar ThaDafinser

parser engine wurfl browser piwik user agent mobile detector useragent device os detection operating system mobile detection ua uaparser browscap get_browser device detection sniffing ua-parser jenssegers sinergi useragentparser rendering engine bot detection whichbrowser woothee ua parser user agent parser user agent detection mobile device detection donatj deviceatlas neutrinoapicom udgercom useragentapicom useragentstringcom whatismybrowsercom

23/03 2016

v1.2.0

1.2.0.0

UserAgentParser abstraction for different parse providers

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar ThaDafinser

parser engine wurfl browser piwik user agent mobile detector useragent device os detection operating system mobile detection ua uaparser browscap get_browser device detection ua-parser jenssegers sinergi useragentparser rendering engine bot detection whichbrowser woothee ua parser user agent parser user agent detection mobile device detection donatj deviceatlas neutrinoapicom udgercom useragentapicom useragentstringcom whatismybrowsercom

17/02 2016

v1.1.0

1.1.0.0

UserAgentParser abstraction for different parse providers

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar ThaDafinser

parser engine wurfl browser piwik user agent mobile detector useragent device os detection operating system mobile detection ua uaparser browscap get_browser device detection sinergi useragentparser rendering engine bot detection whichbrowser woothee ua parser user agent parser user agent detection mobile device detection udger useragentapi useragentstring whatismybrowser

09/02 2016

v1.0.2

1.0.2.0

UserAgentParser abstraction for different parse providers

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar ThaDafinser

parser engine wurfl browser piwik user agent mobile detector useragent device os detection operating system mobile detection ua uaparser browscap get_browser device detection sinergi useragentparser rendering engine bot detection whichbrowser woothee ua parser user agent parser user agent detection mobile device detection udger useragentapi useragentstring whatismybrowser

26/01 2016

v1.0.1

1.0.1.0

UserAgentParser abstraction for different parse providers

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar ThaDafinser

parser engine wurfl browser piwik user agent mobile detector useragent device os detection operating system mobile detection ua uaparser browscap get_browser device detection sinergi useragentparser rendering engine bot detection whichbrowser woothee ua parser user agent parser user agent detection mobile device detection udger useragentapi useragentstring whatismybrowser

12/01 2016

v1.0.0

1.0.0.0

UserAgentParser abstraction for different parse providers

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar ThaDafinser

parser engine wurfl browser piwik user agent mobile detector useragent device os detection operating system mobile detection ua uaparser browscap get_browser device detection sinergi useragentparser rendering engine bot detection whichbrowser woothee ua parser user agent parser user agent detection mobile device detection udger useragentapi useragentstring whatismybrowser

14/12 2015

v0.11.0

0.11.0.0

UserAgentParser abstraction for different parse providers

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar ThaDafinser

parser engine wurfl browser piwik user agent mobile detector useragent device os detection operating system mobile detection ua uaparser browscap get_browser device detection sinergi useragentparser rendering engine bot detection whichbrowser woothee ua parser user agent parser user agent detection mobile device detection udger useragentapi useragentstring whatismybrowser yzalis

11/12 2015

v0.10.0

0.10.0.0

UserAgentParser abstraction for different parse providers

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar ThaDafinser

parser engine wurfl browser piwik user agent mobile detector useragent device os detection operating system mobile detection ua uaparser browscap get_browser device detection sinergi useragentparser rendering engine bot detection whichbrowser woothee ua parser user agent parser user agent detection mobile device detection udger useragentapi useragentstring whatismybrowser yzalis

01/12 2015

v0.9.1

0.9.1.0

UserAgentParser abstraction for different parse providers

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar ThaDafinser

parser browser user agent useragent device os detection operating system mobile detection ua browscap useragentparser rendering engine bot detection whichbrowser woothee phpuseragentparser device detector

30/11 2015

v0.9.0

0.9.0.0

UserAgentParser abstraction for different parse providers

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar ThaDafinser

parser browser user agent useragent device os detection operating system mobile detection ua browscap useragentparser rendering engine bot detection whichbrowser woothee phpuseragentparser device detector

24/11 2015

v0.8.1

0.8.1.0

UserAgentParser abstraction for different parse providers

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar ThaDafinser

parser browser user agent useragent device os detection operating system mobile detection ua browscap useragentparser rendering engine bot detection whichbrowser woothee phpuseragentparser device detector

23/11 2015

v0.8.0

0.8.0.0

UserAgentParser abstraction for different parse providers

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar ThaDafinser

parser browser user agent useragent device os detection operating system mobile detection ua browscap useragentparser rendering engine bot detection whichbrowser woothee phpuseragentparser device detector

17/11 2015

v0.7.0

0.7.0.0

UserAgentParser abstraction for different parse providers

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar ThaDafinser

parser browser user agent useragent device os detection operating system mobile detection ua browscap useragentparser rendering engine bot detection whichbrowser woothee phpuseragentparser device detector

17/11 2015

v0.6.0

0.6.0.0

UserAgentParser abstraction for different parse providers

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar ThaDafinser

parser browser user agent useragent device os detection operating system mobile detection ua browscap useragentparser rendering engine bot detection whichbrowser woothee phpuseragentparser device detector

16/11 2015

v0.5.1

0.5.1.0

UserAgentParser abstraction for different parse providers

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar ThaDafinser

parser browser user agent useragent device os detection operating system mobile detection ua browscap useragentparser rendering engine bot detection whichbrowser woothee phpuseragentparser device detector

16/11 2015

v0.5.0

0.5.0.0

UserAgentParser abstraction for different parse providers

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar ThaDafinser

parser browser user agent useragent device os detection operating system mobile detection ua browscap useragentparser rendering engine bot detection whichbrowser woothee phpuseragentparser device detector

16/11 2015

v0.4.0

0.4.0.0

UserAgentParser abstraction for different parse providers

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar ThaDafinser

parser browser user agent useragent device os detection operating system mobile detection ua browscap useragentparser rendering engine bot detection whichbrowser woothee phpuseragentparser device detector

15/11 2015

v0.3.0

0.3.0.0

UserAgentParser abstraction for different parse providers

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar ThaDafinser

parser browser user agent useragent device os detection operating system mobile detection ua browscap useragentparser rendering engine bot detection whichbrowser woothee phpuseragentparser device detector

12/11 2015

v0.2.2

0.2.2.0

UserAgentParser abstraction for different parse providers

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar ThaDafinser

parser browser user agent useragent device os detection operating system mobile detection ua browscap useragentparser rendering engine bot detection whichbrowser woothee phpuseragentparser device detector

12/11 2015

v0.2.1

0.2.1.0

UserAgentParser abstraction for different parse providers

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar ThaDafinser

parser browser user agent useragent device os detection operating system mobile detection ua browscap useragentparser rendering engine bot detection whichbrowser woothee phpuseragentparser device detector

11/11 2015

v0.2.0

0.2.0.0

UserAgentParser abstraction for different parse providers

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar ThaDafinser

parser browser user agent useragent device os detection operating system mobile detection ua browscap useragentparser rendering engine bot detection whichbrowser woothee phpuseragentparser device detector

10/11 2015

v0.1.0

0.1.0.0

UserAgentParser abstraction for different parse providers

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar ThaDafinser

parser browser user agent useragent device os detection operating system mobile detection ua browscap useragentparser rendering engine bot detection whichbrowser woothee phpuseragentparser device detector