2017 © Pedro PelĂĄez
 

library phpuseragentparser

Simple, streamlined PHP user-agent parser

image

donatj/phpuseragentparser

Simple, streamlined PHP user-agent parser

  • Wednesday, July 25, 2018
  • by donatj
  • Repository
  • 39 Watchers
  • 313 Stars
  • 639,496 Installations
  • PHP
  • 25 Dependents
  • 2 Suggesters
  • 101 Forks
  • 8 Open issues
  • 31 Versions
  • 11 % Grown

The README.md

PHP User Agent Parser

Join the chat at https://gitter.im/PhpUserAgentParser/Lobby, (*1)

Latest Stable Version Total Downloads License ci.yml, (*2)

What It Is

A simple, streamlined PHP user-agent parser!, (*3)

Licensed under the MIT license: https://www.opensource.org/licenses/mit-license.php, (*4)

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

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

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

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

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

OS Versions

User-agent strings are not a reliable source of OS Version!, (*10)

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

All that said, there is the start of a branch to do it 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., (*12)

Undetectable Browsers

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

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)

Requirements

  • php: >=5.4.0
  • ext-ctype: *

Installing

PHP User Agent is available through Packagist via Composer., (*13)

Install the latest version with:, (*14)

composer require 'donatj/phpuseragentparser'

Usage

The classic procedural use is as simple as:, (*15)

<?php

// if you're using composer
require __DIR__ . '/../vendor/autoload.php';

// v0 style global function - @deprecated
$uaInfo = parse_user_agent();
// or
// modern namespaced function
$uaInfo = donatj\UserAgent\parse_user_agent();

echo $uaInfo[donatj\UserAgent\PLATFORM] . PHP_EOL;
echo $uaInfo[donatj\UserAgent\BROWSER] . PHP_EOL;
echo $uaInfo[donatj\UserAgent\BROWSER_VERSION] . PHP_EOL;

The new object-oriented wrapper form:, (*16)

<?php

use donatj\UserAgent\UserAgentParser;

// if you're using composer
require __DIR__ . '/../vendor/autoload.php';

$parser = new UserAgentParser();

// object-oriented call
$ua = $parser->parse();
// or
// command style invocation
$ua = $parser();

echo $ua->platform() . PHP_EOL;
echo $ua->browser() . PHP_EOL;
echo $ua->browserVersion() . PHP_EOL;

Currently Detected Platforms

Predefined helper constants from donatj\UserAgent\Platforms, (*17)

Constant Platform
Platforms::MACINTOSH Macintosh
Platforms::CHROME_OS Chrome OS
Platforms::LINUX Linux
Platforms::WINDOWS Windows
Platforms::ANDROID Android
Platforms::BLACKBERRY BlackBerry
Platforms::FREEBSD FreeBSD
Platforms::IPAD iPad
Platforms::IPHONE iPhone
Platforms::IPOD iPod
Platforms::KINDLE Kindle
Platforms::KINDLE_FIRE Kindle Fire
Platforms::NETBSD NetBSD
Platforms::NEW_NINTENDO_3DS New Nintendo 3DS
Platforms::NINTENDO_3DS Nintendo 3DS
Platforms::NINTENDO_DS Nintendo DS
Platforms::NINTENDO_SWITCH Nintendo Switch
Platforms::NINTENDO_WII Nintendo Wii
Platforms::NINTENDO_WIIU Nintendo WiiU
Platforms::OPENBSD OpenBSD
Platforms::PLAYBOOK PlayBook
Platforms::PLAYSTATION_3 PlayStation 3
Platforms::PLAYSTATION_4 PlayStation 4
Platforms::PLAYSTATION_5 PlayStation 5
Platforms::PLAYSTATION_VITA PlayStation Vita
Platforms::SAILFISH Sailfish
Platforms::SYMBIAN Symbian
Platforms::TIZEN Tizen
Platforms::WINDOWS_PHONE Windows Phone
Platforms::XBOX Xbox
Platforms::XBOX_ONE Xbox One

Currently Detected Browsers

Predefined helper constants from donatj\UserAgent\Browsers, (*18)

Constant Browser
Browsers::ADSBOT_GOOGLE AdsBot-Google
Browsers::ANDROID_BROWSER Android Browser
Browsers::APPLEBOT Applebot
Browsers::BAIDUSPIDER Baiduspider
Browsers::BINGBOT bingbot
Browsers::BLACKBERRY_BROWSER BlackBerry Browser
Browsers::BROWSER Browser
Browsers::BUNJALLOO Bunjalloo
Browsers::CAMINO Camino
Browsers::CHATGPT_USER ChatGPT-User
Browsers::CHROME Chrome
Browsers::CURL curl
Browsers::EDGE Edge
Browsers::FACEBOOKEXTERNALHIT facebookexternalhit
Browsers::FEEDVALIDATOR FeedValidator
Browsers::FIREFOX Firefox
Browsers::GOOGLEBOT Googlebot
Browsers::GOOGLEBOT_IMAGE Googlebot-Image
Browsers::GOOGLEBOT_VIDEO Googlebot-Video
Browsers::GPTBOT GPTBot
Browsers::HEADLESSCHROME HeadlessChrome
Browsers::IEMOBILE IEMobile
Browsers::IMESSAGEBOT iMessageBot
Browsers::KINDLE Kindle
Browsers::LYNX Lynx
Browsers::MASTODON Mastodon
Browsers::MIDORI Midori
Browsers::MIUIBROWSER MiuiBrowser
Browsers::MSIE MSIE
Browsers::MSNBOT_MEDIA msnbot-media
Browsers::NETFRONT NetFront
Browsers::NINTENDOBROWSER NintendoBrowser
Browsers::OAI_SEARCHBOT OAI-SearchBot
Browsers::OCULUSBROWSER OculusBrowser
Browsers::OPERA Opera
Browsers::PUFFIN Puffin
Browsers::SAFARI Safari
Browsers::SAILFISHBROWSER SailfishBrowser
Browsers::SAMSUNGBROWSER SamsungBrowser
Browsers::SILK Silk
Browsers::SLACKBOT Slackbot
Browsers::TELEGRAMBOT TelegramBot
Browsers::TIZENBROWSER TizenBrowser
Browsers::TWITTERBOT Twitterbot
Browsers::UC_BROWSER UC Browser
Browsers::VALVE_STEAM_TENFOOT Valve Steam Tenfoot
Browsers::VIVALDI Vivaldi
Browsers::WGET Wget
Browsers::WHALE Whale
Browsers::WORDPRESS WordPress
Browsers::YANDEX Yandex
Browsers::YANDEXBOT YandexBot

More information is available at Donat Studios., (*19)

The Versions

25/07 2018

dev-constants

dev-constants http://donatstudios.com/PHP-Parser-HTTP_USER_AGENT

Simple, streamlined PHP user-agent parser

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

parser browser user agent useragent browser detection

21/06 2018

dev-master

9999999-dev http://donatstudios.com/PHP-Parser-HTTP_USER_AGENT

Simple, streamlined PHP user-agent parser

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

parser browser user agent useragent browser detection

21/06 2018

v0.10.0

0.10.0.0 http://donatstudios.com/PHP-Parser-HTTP_USER_AGENT

Simple, streamlined PHP user-agent parser

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

parser browser user agent useragent browser detection

28/01 2018

dev-patch-1

dev-patch-1 http://donatstudios.com/PHP-Parser-HTTP_USER_AGENT

Simple, streamlined PHP user-agent parser

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

parser browser user agent useragent browser detection

23/10 2017

v0.9.0

0.9.0.0 http://donatstudios.com/PHP-Parser-HTTP_USER_AGENT

Simple, streamlined PHP user-agent parser

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

parser browser user agent useragent browser detection

23/10 2017

v0.8.0

0.8.0.0 http://donatstudios.com/PHP-Parser-HTTP_USER_AGENT

Simple, streamlined PHP user-agent parser

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

parser browser user agent useragent browser detection

01/03 2017

v0.7.0

0.7.0.0 http://donatstudios.com/PHP-Parser-HTTP_USER_AGENT

Simple, streamlined PHP user-agent parser

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

parser browser user agent useragent browser detection

23/01 2017

v0.6.0

0.6.0.0 http://donatstudios.com/PHP-Parser-HTTP_USER_AGENT

Simple, streamlined PHP user-agent parser

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

parser browser user agent useragent browser detection

16/12 2016

v0.5.3

0.5.3.0 http://donatstudios.com/PHP-Parser-HTTP_USER_AGENT

Simple, streamlined PHP user-agent parser

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

parser browser user agent useragent browser detection

02/09 2016

v0.5.2

0.5.2.0 http://donatstudios.com/PHP-Parser-HTTP_USER_AGENT

Simple, streamlined PHP user-agent parser

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

parser browser user agent useragent browser detection

07/03 2016

v0.5.1

0.5.1.0 http://donatstudios.com/PHP-Parser-HTTP_USER_AGENT

Simple, streamlined PHP user-agent parser

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

parser browser user agent useragent browser detection

17/02 2016

dev-os_version_detection

dev-os_version_detection http://donatstudios.com/PHP-Parser-HTTP_USER_AGENT

Simple, streamlined PHP user-agent parser

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

parser browser user agent useragent browser detection

22/09 2015

v0.5.0

0.5.0.0 http://donatstudios.com/PHP-Parser-HTTP_USER_AGENT

Simple, streamlined PHP user-agent parser

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

parser browser user agent useragent browser detection

25/08 2015

v0.4.0

0.4.0.0 http://donatstudios.com/PHP-Parser-HTTP_USER_AGENT

Simple, streamlined PHP user-agent parser

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

parser browser user agent useragent browser detection

23/04 2015

v0.3.6

0.3.6.0 http://donatstudios.com/PHP-Parser-HTTP_USER_AGENT

Simple, streamlined PHP user-agent parser

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

parser user agent useragent

26/03 2015

v0.3.5

0.3.5.0 http://donatstudios.com/PHP-Parser-HTTP_USER_AGENT

Simple, streamlined PHP user-agent parser

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

parser user agent useragent

20/02 2015

v0.3.4

0.3.4.0 http://donatstudios.com/PHP-Parser-HTTP_USER_AGENT

Simple, streamlined PHP user-agent parser

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

parser user agent useragent

01/02 2015

v0.3.3

0.3.3.0 http://donatstudios.com/PHP-Parser-HTTP_USER_AGENT

Simple, streamlined PHP user-agent parser

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

parser user agent useragent

22/12 2014

v0.3.2

0.3.2.0 http://donatstudios.com/PHP-Parser-HTTP_USER_AGENT

Simple, streamlined PHP user-agent parser

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

parser user agent useragent

27/10 2014

v0.3.1

0.3.1.0 http://donatstudios.com/PHP-Parser-HTTP_USER_AGENT

Simple, streamlined PHP user-agent parser

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

parser user agent useragent

07/10 2014

v0.3.0

0.3.0.0 http://donatstudios.com/PHP-Parser-HTTP_USER_AGENT

Simple, streamlined PHP user-agent parser

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

parser user agent useragent

06/08 2014

v0.2.2

0.2.2.0 http://donatstudios.com/PHP-Parser-HTTP_USER_AGENT

Simple, streamlined PHP user-agent parser

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

parser user agent useragent

16/04 2014

v0.2.1

0.2.1.0 http://donatstudios.com/PHP-Parser-HTTP_USER_AGENT

Simple, streamlined PHP user-agent parser

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

parser user agent useragent

12/04 2014

v0.2.0

0.2.0.0 http://donatstudios.com/PHP-Parser-HTTP_USER_AGENT

Simple, streamlined PHP user-agent parser

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

parser user agent useragent

12/03 2014

v0.1.6

0.1.6.0 http://donatstudios.com/PHP-Parser-HTTP_USER_AGENT

Simple, streamlined PHP user-agent parser

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

parser user agent useragent

25/11 2013

v0.1.5

0.1.5.0 http://donatstudios.com/PHP-Parser-HTTP_USER_AGENT

Simple, streamlined PHP user-agent parser

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

parser user agent useragent

19/11 2013

v0.1.4

0.1.4.0 http://donatstudios.com/PHP-Parser-HTTP_USER_AGENT

Simple, streamlined PHP user-agent parser

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

parser user agent useragent

14/10 2013

v0.1.3

0.1.3.0 http://donatstudios.com/PHP-Parser-HTTP_USER_AGENT

Simple, streamlined PHP user-agent parser

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

parser user agent useragent

10/10 2013

v0.1.2

0.1.2.0 http://donatstudios.com/PHP-Parser-HTTP_USER_AGENT

Simple user agent string parser

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

parser user agent

10/10 2013

v0.1.1

0.1.1.0 http://donatstudios.com/PHP-Parser-HTTP_USER_AGENT

Simple user agent string parser

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

parser user agent

24/07 2013

v0.1.0

0.1.0.0 http://donatstudios.com/PHP-Parser-HTTP_USER_AGENT

Simple user agent string parser

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

parser user agent