PHP User Agent Parser

June 16, 2026 · View on GitHub

Join the chat at https://gitter.im/PhpUserAgentParser/Lobby

Latest Stable Version Total Downloads License ci.yml

What It Is

A simple, streamlined PHP user-agent parser!

Licensed under the MIT license: https://www.opensource.org/licenses/mit-license.php

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

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

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

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 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

  • 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.

Install the latest version with:

composer require 'donatj/phpuseragentparser'

Usage

The classic procedural use is as simple as:

<?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:

<?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 Tested Platforms

Predefined helper constants from donatj\UserAgent\Platforms

ConstantPlatform
Platforms::MACINTOSHMacintosh
Platforms::CHROME_OSChrome OS
Platforms::LINUXLinux
Platforms::WINDOWSWindows
Platforms::ANDROIDAndroid
Platforms::BLACKBERRYBlackBerry
Platforms::FREEBSDFreeBSD
Platforms::FUCHSIAFuchsia
Platforms::IPADiPad
Platforms::IPHONEiPhone
Platforms::IPODiPod
Platforms::KINDLEKindle
Platforms::KINDLE_FIREKindle Fire
Platforms::NETBSDNetBSD
Platforms::NEW_NINTENDO_3DSNew Nintendo 3DS
Platforms::NINTENDO_3DSNintendo 3DS
Platforms::NINTENDO_DSNintendo DS
Platforms::NINTENDO_SWITCHNintendo Switch
Platforms::NINTENDO_WIINintendo Wii
Platforms::NINTENDO_WIIUNintendo WiiU
Platforms::OPENBSDOpenBSD
Platforms::PLAYBOOKPlayBook
Platforms::PLAYSTATION_3PlayStation 3
Platforms::PLAYSTATION_4PlayStation 4
Platforms::PLAYSTATION_5PlayStation 5
Platforms::PLAYSTATION_VITAPlayStation Vita
Platforms::SAILFISHSailfish
Platforms::SYMBIANSymbian
Platforms::TIZENTizen
Platforms::WINDOWS_PHONEWindows Phone
Platforms::XBOXXbox
Platforms::XBOX_ONEXbox One

Currently Tested Browsers

Note

There is overlap between browsers and bots. Before bots were given their own separate class, a number were added to the browser list. They appear in both lists for backward compatibility. This is likely to be remedied should there be a future major release.

Predefined helper constants from donatj\UserAgent\Browsers

ConstantBrowser
Browsers::ADSBOT_GOOGLEAdsBot-Google
Browsers::ANDROID_BROWSERAndroid Browser
Browsers::APPLEBOTApplebot
Browsers::BAIDUSPIDERBaiduspider
Browsers::BINGBOTbingbot
Browsers::BLACKBERRY_BROWSERBlackBerry Browser
Browsers::BROWSERBrowser
Browsers::BUNJALLOOBunjalloo
Browsers::CAMINOCamino
Browsers::CHATGPT_USERChatGPT-User
Browsers::CHROMEChrome
Browsers::CURLcurl
Browsers::EDGEEdge
Browsers::FACEBOOKEXTERNALHITfacebookexternalhit
Browsers::FEEDVALIDATORFeedValidator
Browsers::FIREFOXFirefox
Browsers::GOOGLEBOTGooglebot
Browsers::GOOGLEBOT_IMAGEGooglebot-Image
Browsers::GOOGLEBOT_VIDEOGooglebot-Video
Browsers::GPTBOTGPTBot
Browsers::HEADLESSCHROMEHeadlessChrome
Browsers::IEMOBILEIEMobile
Browsers::IMESSAGEBOTiMessageBot
Browsers::KINDLEKindle
Browsers::LYNXLynx
Browsers::MASTODONMastodon
Browsers::MIDORIMidori
Browsers::MIUIBROWSERMiuiBrowser
Browsers::MSIEMSIE
Browsers::MSNBOT_MEDIAmsnbot-media
Browsers::NETFRONTNetFront
Browsers::NINTENDOBROWSERNintendoBrowser
Browsers::OAI_SEARCHBOTOAI-SearchBot
Browsers::OCULUSBROWSEROculusBrowser
Browsers::OPERAOpera
Browsers::PUFFINPuffin
Browsers::SAFARISafari
Browsers::SAILFISHBROWSERSailfishBrowser
Browsers::SAMSUNGBROWSERSamsungBrowser
Browsers::SILKSilk
Browsers::SLACKBOTSlackbot
Browsers::TELEGRAMBOTTelegramBot
Browsers::TIZENBROWSERTizenBrowser
Browsers::TWITTERBOTTwitterbot
Browsers::UC_BROWSERUC Browser
Browsers::VALVE_STEAM_TENFOOTValve Steam Tenfoot
Browsers::VIVALDIVivaldi
Browsers::WGETWget
Browsers::WHALEWhale
Browsers::WORDPRESSWordPress
Browsers::YANDEXYandex
Browsers::YANDEXBOTYandexBot
Browsers::YETIYeti

Tested Bots

Predefined helper constants from donatj\UserAgent\Bots

ConstantBots
Bots::ADKERNELTOPICCRAWLERAdkernelTopicCrawler
Bots::ADSBOT_GOOGLEAdsBot-Google
Bots::AHREFSBOTAhrefsBot
Bots::AHREFSSITEAUDITAhrefsSiteAudit
Bots::AMAZONADBOTAmazonAdBot
Bots::AMAZONBOTAmazonbot
Bots::APPLEBOTApplebot
Bots::ARCHIVE_ORG_BOTarchive.org_bot
Bots::AWARIOBOTAwarioBot
Bots::BAIDUSPIDERBaiduspider
Bots::BAIDUSPIDER_RENDERBaiduspider-render
Bots::BARKROWLERBarkrowler
Bots::BINGBOTbingbot
Bots::BLEXBOTBLEXBot
Bots::BRAVEBOTBravebot
Bots::CENSYSINSPECTCensysInspect
Bots::CHATGPT_USERChatGPT-User
Bots::CLAUDEBOTClaudeBot
Bots::COCCOCBOT_IMAGEcoccocbot-image
Bots::COCCOCBOT_WEBcoccocbot-web
Bots::CURLcurl
Bots::DATAFORSEOBOTDataForSeoBot
Bots::DISCORDBOTDiscordbot
Bots::DOTBOTDotBot
Bots::DVBOTDVbot
Bots::EV_CRAWLERev-crawler
Bots::FACEBOOKEXTERNALHITfacebookexternalhit
Bots::FEEDBOTfeedbot
Bots::FEEDVALIDATORFeedValidator
Bots::GOOGLEBOTGooglebot
Bots::GOOGLEBOT_IMAGEGooglebot-Image
Bots::GOOGLEBOT_VIDEOGooglebot-Video
Bots::GOOGLE_READ_ALOUDGoogle-Read-Aloud
Bots::GOOGLE_SAFETYGoogle-Safety
Bots::GPTBOTGPTBot
Bots::HEEXYBOTHeexybot
Bots::HUBSPOT_DOMAIN_CHECKHubSpot Domain check
Bots::IBOUBOTIbouBot
Bots::IMESSAGEBOTiMessageBot
Bots::LEIKIBOTLeikibot
Bots::MASTODONMastodon
Bots::MINIFLUXMiniflux
Bots::MODATSCANNERModatScanner
Bots::MOJEEKBOTMojeekBot
Bots::MSNBOT_MEDIAmsnbot-media
Bots::OAI_SEARCHBOTOAI-SearchBot
Bots::PERPLEXITYBOTPerplexityBot
Bots::PERPLEXITY_USERPerplexity-User
Bots::PETALBOTPetalBot
Bots::PINTERESTBOTPinterestbot
Bots::PROXIMICproximic
Bots::SCOURRSSBOTScourRSSBot
Bots::SEMRUSHBOTSemrushBot
Bots::SEMRUSHBOT_SISemrushBot-SI
Bots::SERANKINGBACKLINKSBOTSERankingBacklinksBot
Bots::SEZNAMBOTSeznamBot
Bots::SLACKBOTSlackbot
Bots::SMTBOTSMTBot
Bots::SPIDERLINGSpiderLing
Bots::SURDOTLYBOTSurdotlyBot
Bots::TELEGRAMBOTTelegramBot
Bots::TWITTERBOTTwitterbot
Bots::WELLKNOWNBOTWellKnownBot
Bots::WGETWget
Bots::WORDPRESSWordPress
Bots::WPBOTwpbot
Bots::YANDEXBOTYandexBot
Bots::YANDEXIMAGESYandexImages
Bots::YANDEXMOBILEBOTYandexMobileBot
Bots::YANDEXRCAYandexRCA
Bots::YANDEXUSERPROXYYandexUserproxy
Bots::YETIYeti

More information is available at Donat Studios.