Parses a User Agent string and returns a \hexydec\agentzero\agentzero object on success, or false if the string could not be parsed (e.g. empty string, longer than 2000 characters, or produces no recognisable tokens).
The optional $hints parameter accepts an array of Client Hint header values. The optional $config parameter accepts an array of configuration options.
The returned object has the following properties:
Indicates whether the UA string is a human or a robot
The category of device, possible values where the type is human are:
desktoptabletmobilevrtvconsole
For robots the possible values are:
searchadscrawlerfeedscrapervalidatormonitor
The name of the device vendor.
The name of device.
The device model number.
The build number of the device software.
The amount of RAM in the device in megabytes, as reported by the Device-Memory client hint.
The vendor name of the processor manufacturer.
The system architecture, possible values are:
x86itaniumarmSunSpark V9
The number of bits, either 32 or 64.
The CPU model identifier as reported in the UA string.
The CPU clock speed in MHz as reported in the UA string.
The name of the kernel, e.g. Linux
The platform name
The platform version number
The name of the rendering engine, possible values are:
GeckoBlinkWebKitPrestoTridentGoanna
The version number of the rendering engine
The name of the browser, e.g. Firefox or Chrome
The browser version number
The date the browser version was released.
The current status of the browser:
nightly: A nightly build (3 major versions ahead of latest)canary: A canary build (2 major versions ahead of latest)beta: A beta build (1 major version ahead of latest)current: The browser is the current versionprevious: The browser is a previous versionoutdated: The browser was released 2 or more years agolegacy: The browser was released more than 5 years ago
Requires versionscache to be set in $config. Returns null if version data is unavailable.
The version number of the latest browser from this vendor.
The language code, e.g. en or en-GB, this will be normalised with lowercase, dash, uppercase format
The name of the app (Normalised), e.g. Facebook or YaSearchBrowser. For robots it will be the name of the robot, e.g. GoogleBot
The name of the app or robot as it is written in the User-Agent string
The version number of the application
The app framework used to build the app
The version of tthe app framework
The URL of the robot.
The network connection type as reported by the ECT client hint, e.g. 4g, 3g, 2g, slow-2g.
If the browser session is routed through a proxy, it will be here, e.g. googleweblight
The width of the device screen.
The height of the device screen.
The pixel density of the device screen.
The dots per inch of the device screen.
true if the device is in dark mode, as reported in the UA string. null if unknown.
The following read-only properties are calculated on access via __get() and return int|null:
| Property | Returns |
|---|---|
browsermajorversion |
Integer major version of browserversion |
enginemajorversion |
Integer major version of engineversion |
platformmajorversion |
Integer major version of platformversion |
appmajorversion |
Integer major version of appversion |
host |
Hostname from url, with any www. prefix stripped. Returns null if url is null. |
Use agentzero::getHints(?array $headers = null) : array to extract relevant client hint headers. Pass null (or omit the argument) to read from $_SERVER, or pass an associative array of HTTP header name → value pairs for testing or non-$_SERVER environments. Header names are matched case-insensitively.
Recognised hint headers: Sec-CH-UA-Mobile, Sec-CH-UA-Full-Version-List, Sec-CH-UA-Platform, Sec-CH-UA-Platform-Version, Sec-CH-UA-Model, Device-Memory, Width, ECT.
The $config array passed to parse() supports the following keys:
| Key | Type | Default | Description |
|---|---|---|---|
versionscache |
string|null |
null |
Absolute path to the local JSON cache file for browser version data. Version properties (browserstatus, browserreleased, browserlatest) are null unless this is set. |
versionssource |
string |
GitHub URL | URL of the remote versions JSON file. Only fetched when the cache is missing or stale. |
versionscachelife |
int |
604800 |
Cache TTL in seconds (default: 7 days). |
currentdate |
\DateTime|null |
null |
Pin the "current date" used when calculating browserstatus. Useful for reproducible tests or historical analysis. |