{"id":13453475,"url":"https://github.com/WhichBrowser/Parser-PHP","last_synced_at":"2025-03-24T01:31:34.380Z","repository":{"id":9220595,"uuid":"11034722","full_name":"WhichBrowser/Parser-PHP","owner":"WhichBrowser","description":"Browser sniffing gone too far — A useragent parser library for PHP","archived":false,"fork":false,"pushed_at":"2024-05-19T10:06:29.000Z","size":11247,"stargazers_count":1801,"open_issues_count":24,"forks_count":237,"subscribers_count":78,"default_branch":"master","last_synced_at":"2024-10-29T11:32:27.587Z","etag":null,"topics":["library","php","user-agent","whichbrowser"],"latest_commit_sha":null,"homepage":"http://whichbrowser.net","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/WhichBrowser.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2013-06-28T18:45:49.000Z","updated_at":"2024-10-27T12:59:33.000Z","dependencies_parsed_at":"2024-04-16T12:39:02.301Z","dependency_job_id":"0d181c24-7e9e-4aef-a53a-fa61117467ac","html_url":"https://github.com/WhichBrowser/Parser-PHP","commit_stats":{"total_commits":1724,"total_committers":25,"mean_commits":68.96,"dds":0.3346867749419954,"last_synced_commit":"1044880bc792dbce5948fbff22ae731c43c280d9"},"previous_names":["nielsleenheer/whichbrowser","whichbrowser/whichbrowser","whichbrowser/parser"],"tags_count":59,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WhichBrowser%2FParser-PHP","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WhichBrowser%2FParser-PHP/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WhichBrowser%2FParser-PHP/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WhichBrowser%2FParser-PHP/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/WhichBrowser","download_url":"https://codeload.github.com/WhichBrowser/Parser-PHP/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245036146,"owners_count":20550661,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["library","php","user-agent","whichbrowser"],"created_at":"2024-07-31T08:00:40.693Z","updated_at":"2025-03-24T01:31:33.348Z","avatar_url":"https://github.com/WhichBrowser.png","language":"PHP","readme":"\u003cimg src=\"https://api.whichbrowser.net/whichbrowser.svg\" width=\"400\"\u003e\n\nThis is an extremely complicated and almost completely useless browser sniffing library. Useless because you shouldn't use browser sniffing. So stop right now and go read something about feature detecting instead. I'm serious. Go away. You'll thank me later.\n\n\nWhichBrowser/Parser-PHP\n=======================\n\nThe PHP version of WhichBrowser for use on a server. Fully compatible with PHP 7.0 or higher, including PHP 8.\n\n![Build](https://github.com/WhichBrowser/Parser-PHP/workflows/Build/badge.svg)\n[![Coverage Status](https://coveralls.io/repos/WhichBrowser/Parser-PHP/badge.svg?branch=master\u0026service=github)](https://coveralls.io/github/WhichBrowser/Parser-PHP?branch=master)\n[![License](https://poser.pugx.org/whichbrowser/parser/license)](https://packagist.org/packages/whichbrowser/parser)\n[![Latest Stable Version](https://poser.pugx.org/whichbrowser/parser/v/stable)](https://packagist.org/packages/whichbrowser/parser)\n\n[![Twitter Follow](https://img.shields.io/twitter/follow/whichbrowserlib.svg?style=social)](https://twitter.com/whichbrowserlib)\n\nAlso available:\n\n- [WhichBrowser/Parser-JavaScript](https://github.com/WhichBrowser/Parser-JavaScript)\u003cbr\u003e\n  A JavaScript version of WhichBrowser for use with Node.js on the server\n\n- [WhichBrowser/Server](https://github.com/WhichBrowser/Server)\u003cbr\u003e\n  A server written in PHP that provides a JavaScript API for use in the browser\n\n---\n\n\nAbout WhichBrowser\n------------------\n\n**But why *almost completely useless* and not completely useless?**\nWell, there is always an exception to the rule. There are valid reasons to do browser sniffing: to improve the user experience or to gather intelligence about which browsers are used on your website. My website is html5test.com and I wanted to know which score belongs to which browser. And to do that you need a browser sniffing library.\n\n**Why is it extremely complicated?**  \nBecause everybody lies. Seriously, there is not a single browser that is completely truthful. Almost all browsers say they are Netscape 5 and almost all WebKit browsers say they are based on Gecko. Even Internet Explorer 11 now no longer claims to be IE at all, but instead an unnamed browser that is like Gecko. And it gets worse. That is why it is complicated.\n\n**What kind of information does it give?**\nYou get a nice object which has information about the browser, rendering engine, os and device. It gives you names and versions and even device manufacturer and model. And WhichBrowser is pretty tenacious. It gives you info that others don't. For example:\n\n    JUC (Linux; U; 2.3.6; zh-cn; GT-I8150; 480*800) UCWEB8.7.4.225/145/800  \n    UC Browser 8.7 on a Samsung Galaxy W running Android 2.3.6\n\nAndroid is never mentioned\n\n    Mozilla/5.0 (Series40; Nokia501/10.0.2; Profile/MIDP-2.1 Configuration/CLDC-1.1) Gecko/20100401 S40OviBrowser/3.0.0.0.73  \n    Nokia Xpress 3.0.0 on a Nokia Asha 501 running Nokia Asha Platform\n\nDespite the useragent header claiming to be a Series40 device, we know it's actually running the Asha Platform and we also know that OviBrowser has been renamed to Nokia Xpress.\n\n    Opera/9.80 (X11; Linux zvav; U; zh) Presto/2.8.119 Version/11.10  \n    Opera Mini on a Nokia 5230 running Series60 5.0\n\nThe useragent header looks like Opera 11.10 on Linux, but we know it's Opera Mini. We can even figure out the real operating system and device model from other headers.\n\n\n\nRequirements\n-----------------\n\nWhichBrowser requires with PHP 7.0 or higher and supports PHP 8. WhichBrowser is compatible with the PSR-4 autoloading standard and follows PSR-1 and PSR-2 coding style.\n\n\nHow to install it\n-----------------\n\nYou can install WhichBrowser by using Composer - the standard package manager for PHP. The package is called `whichbrowser/parser`.\n\n    composer require whichbrowser/parser\n\nYou can easily update WhichBrowser by running a simple command.\n\n    composer update whichbrowser/parser\n\nYou should run this command as often as possible. You might even want to consider setting up a cron job for this purpose.\n\n\n\n\nHow to use it\n-------------\n\nThe first step require the Composer autoloader:\n\n```php\n\u003c?php\n\n    require 'vendor/autoload.php';\n```\n\nThe second step is to create a new `WhichBrowser\\Parser` object. This object will contain all the information the library could find about the browser. The object has a required parameter, either the headers send by the browser, or a useragent string. Using the headers is preferable, because it will allow a better detection, but if you have just the useragent string, this will also work.\n\nFor example:\n\n```php\n$result = new WhichBrowser\\Parser(getallheaders());\n```\n\nor:\n\n```php\n$result = new WhichBrowser\\Parser($_SERVER['HTTP_USER_AGENT']);\n```\n\n\nThe variable `$result` now contains an object which you can query for information. There are various ways to access the information.\n\n\nFirst of all, you can call to `toString()` function to get a human readable identification:\n\n```php\n\"You are using \" . $result-\u003etoString();\n// You are using Chrome 27 on OS X Mountain Lion 10.8\n```\n\nAnother possiblity is to query the object:\n\n```php\n$result-\u003eisType('desktop');\n// true\n\n$result-\u003eisType('mobile', 'tablet', 'media', 'gaming:portable');\n// false\n\n$result-\u003eisBrowser('Maxthon', '\u003c', '4.0.5');\n// false\n\n$result-\u003eisOs('iOS', '\u003e=', '8');\n// false\n\n$result-\u003eisOs('OS X');\n// true\n\n$result-\u003eisEngine('Blink');\n// true\n```\n\nYou can also access these properties directly:\n\n```php\n$result-\u003ebrowser-\u003etoString();\n// Chrome 27  \n\n$result-\u003eengine-\u003etoString();\n// Blink\n\n$result-\u003eos-\u003etoString();\n// OS X Mountain Lion 10.8\n```\n\nOr access parts of these properties directly:\n\n```php\n$result-\u003ebrowser-\u003ename;\n// Chrome\n\n$result-\u003ebrowser-\u003ename . ' ' . $result-\u003ebrowser-\u003eversion-\u003etoString();\n// Chrome 27\n\n$result-\u003ebrowser-\u003eversion-\u003evalue;\n// 27.0.1453.110\n\n$result-\u003eengine-\u003ename;\n// Blink\n```\n\nFinally you can also query versions directly:\n\n```php\n$result-\u003ebrowser-\u003eversion-\u003eis('\u003e', 26);\n// true\n\n$result-\u003eos-\u003eversion-\u003eis('\u003c', '10.7.4');\n// false\n```\n\nOptions\n-------\n\nIt is possible to set additional options by passing an array as the second parameter when creating the `Parser` object.\n\n### Disabling detection of bots\n\nIn some cases you may want to disable the detection of bots. This allows the bot the deliberately fool WhichBrowser, so you can pick up the identity of useragent what the bot tries to mimic. This is especially handy when you want to use WhichBrowser to switch between different variants of your website and want to make sure crawlers see the right variant of the website. For example, a bot that mimics a mobile device will see the mobile variant of you site.\n\n```php\n$result = new WhichBrowser\\Parser(getallheaders(), [ 'detectBots' =\u003e false ]);\n```\n\nEnable result caching\n---------------------\n\nWhichBrowser supports PSR-6 compatible cache adapters for caching results between requests. Using a cache is especially useful if you use WhichBrowser on every page of your website and a user visits multiple pages. During the first visit the headers will be parsed and the result will be cached. Upon further visits, the cached results will be used, which is much faster than having to parse the headers again and again.\n\nThere are adapters available for other types of caches, such as APC, Doctrine, Memcached, MongoDB, Redis and many more. The configuration of these adapters all differ from each other, but once configured, all you have to do is pass it as an option when creating the `Parser` object, or use the `setCache()` function to set it afterwards. WhichBrowser has been tested to work with the adapters provided by [PHP Cache](http://php-cache.readthedocs.org/en/latest/). For a list of other packages that provide adapters see [Packagist](https://packagist.org/providers/psr/cache-implementation).\n\nFor example, if you want to enable a memcached based cache you need to install an extra composer package:\n\n    composer require cache/memcached-adapter\n\nAnd change the call to WhichBrowser/Parser as follows:\n\n```php\n$client = new \\Memcached();\n$client-\u003eaddServer('localhost', 11211);\n\n$pool = new \\Cache\\Adapter\\Memcached\\MemcachedCachePool($client);\n\n$result = new WhichBrowser\\Parser(getallheaders(), [ 'cache' =\u003e $pool ]);\n```\n\nor\n\n```php\n$client = new \\Memcached();\n$client-\u003eaddServer('localhost', 11211);\n\n$pool = new \\Cache\\Adapter\\Memcached\\MemcachedCachePool($client);\n\n$result = new WhichBrowser\\Parser();\n$result-\u003esetCache($pool);\n$result-\u003eanalyse(getallheaders());\n```\n\nYou can also specify after how many seconds a cached result should be discarded. The default value is 900 seconds or 15 minutes. If you think WhichBrowser uses too much memory for caching, you should lower this value. You can do this by setting the `cacheExpires` option or passing it as a second parameter to the `setCache()` function.\n\n\nAPI reference\n-------------\n\n### The Parser object\n\nAfter a new `WhichBrowser\\Parser` object is created, it contains a number of properties and functions. All of these properties are guaranteed to be present.\n\n**Properties:**\n\n* `browser`  \n  an object that contains information about the browser itself\n* `engine`  \n  an object that contains information about the rendering engine\n* `os`  \n  an object that contains information about the operating system\n* `device`  \n  an object that contains information about the device\n\n**Functions:**\n\n`getType()`  \nReturns the `type` and `subtype` property of the `device` object. If a subtype is present it is concatenated to the type and seperated by a semicolor, for example: `mobile:smart` or `gaming:portable`. If the subtype is not applicable, it just return the type, for example: `desktop` or `ereader`.\n\n`isType($type [,$type [,$type [,$type]]])`  \nIf a single argument is used, the function returns `true` if the argument matches the `type` propery of `device` object. The argument can optionally also provide a subtype by concatenating it to the type and seperating it with a semicolon. It can use multiple arguments in which case the function returns `true` if one of the arguments matches. If none of the arguments matches, it returns `false`\n\n`isMobile()`  \nReturn `true` if the browser is a mobile device, like a phone, tablet, ereader, camera, portable media player, watch or portable gaming console. Otherwise it returns `false`.\n\n`isBrowser($name [, $comparison, $version])`  \nIs used to query the `name` and `version` property of the `browser` object. The funcion can contain a single argument to a simple comparison based on `name`, or three arguments to compare both `name` and `version`. The first argument always contains the name of the browser. The second arguments is a string that can container either `\u003c`, `\u003c=`, `=`, `=\u003e` or `\u003e`. The third is an integer, float or string that contains the version. You can use versions like `10`, `10.7` or `'10.7.4'`. For more information about how version comparisons are performed, please see the `is()` function of the `Version` object.\n\n`isEngine($name [, $comparison, $version])`  \nIs used to query the `name` and `version` property of the `engine` object. This function works in exactly the same way as `isBrowser`.\n\n`isOs($name [, $comparison, $version])`  \nIs used to query the `name` and `version` property of the `os` object. This function works in exactly the same way as `isBrowser`.\n\n`isDetected()`  \nIs there actually some browser detected, or did we fail to detect anything?\n\n`toString()`  \nGet a human readable representation of the detected browser, including operating system and device information.\n\n\n### The browser object\n\nAn object of the `WhichBrowser\\Model\\Browser` class is used for the `browser` property of the main `WhichBrowser\\Parser` object and contains a number of properties. If a property is not applicable in this situation it will be null or undefined.\n\n**Properties:**\n\n* `name`  \n  a string containing the name of the browser\n* `alias`  \n  a string containing an alternative name of the browser\n* `version`  \n  a version object containing information about the version of the browser\n* `stock`  \n  a boolean, true if the browser is the default browser of the operating system, false otherwise\n* `channel`  \n  a string containing the distribution channel, ie. 'Nightly' or 'Next'.\n* `mode`  \n  a string that can contain the operating mode of the browser, ie. 'proxy'.\n* `hidden`  \n  a boolean that is true if the browser does not have a name and is the default of the operating system.\n* `family`  \n  an object that contains information about to which family this browser belongs\n* `using`  \n  an object that contains information about to which kind of webview this browser uses\n\n**Functions:**\n\n`isFamily($name)`  \nDoes the family of this browser have this name, or does the browser itself have this name.\n\n`isUsing($name)`  \nIs the browser using a webview using with the provided name.\n\n`getName()`  \nGet the name of the browser\n\n`getVersion()`  \nGet the version of the browser\n\n`toString()`  \nGet a human readable representation of the detected browser\n\n\n### The engine object\n\nAn object of the `WhichBrowser\\Model\\Engine` class is used for the `engine` property of the main `WhichBrowser\\Parser` object and contains a number of properties. If a property is not applicable in this situation it will be null or undefined.\n\n**Properties:**\n\n* `name`  \n  a string containing the name of the rendering engine\n* `version`  \n  a version object containing information about the version of the rendering engine\n\n**Functions:**\n\n`getName()`  \nGet the name of the rendering engine\n\n`getVersion()`  \nGet the version of the rendering engine\n\n`toString()`  \nGet a human readable representation of the detected rendering engine\n\n\n### The os object\n\nAn object of the `WhichBrowser\\Model\\Os` class is used for the `os` property of the main `WhichBrowser\\Parser` object and contains a number of properties. If a property is not applicable in this situation it will be null or undefined.\n\n**Properties:**\n\n* `name`  \n  a string containing the name of the operating system\n* `version`  \n  a version object containing information about the version of the operating system\n* `family`  \n  an object that contains information about to which family this operating system belongs\n\n**Functions:**\n\n`isFamily($name)`  \nDoes the family of this operating system have this name, or does the operating system itself have this name.\n\n`getName()`  \nGet the name of the operating system\n\n`getVersion()`  \nGet the version of the operating system\n\n`toString()`  \nGet a human readable representation of the detected operating system\n\n\n### The device object\n\nAn object of the `WhichBrowser\\Model\\Device` class is used for the `device` property of the main `WhichBrowser\\Parser` object and contains a number of properties. If a property is not applicable in this situation it will be null or undefined.\n\n**Properties:**\n\n* `type`  \n  a string containing the type of the browser.\n* `subtype`  \n  a string containing the subtype of the browser.\n* `identified`  \n  a boolean that is true if the device has been positively identified.\n* `manufacturer`  \n  a string containing the manufacturer of the device, ie. 'Apple' or 'Samsung'.\n* `model`  \n  as string containing the model of the device, ie. 'iPhone' or 'Galaxy S4'.\n\nThe `type` property can contain any value from the following list:\n\n* desktop\n* mobile\n* pda\n* dect\n* tablet\n* gaming\n* ereader\n* media\n* headset\n* watch\n* emulator\n* television\n* monitor\n* camera\n* printer\n* signage\n* whiteboard\n* devboard\n* inflight\n* appliance\n* gps\n* car\n* pos\n* bot\n* projector\n\nIf the `type` is \"mobile\", the `subtype` property can contain any value from the following list:\n\n* feature\n* smart\n\nIf the `type` is \"gaming\", the `subtype` property can contain any value from the following list:\n\n* console\n* portable\n\n**Functions:**\n\n`getManufacturer()`  \nGet the name of the manufacturer\n\n`getModel()`  \nGet the name of the model\n\n`toString()`  \nGet a human readable representation of the detected device\n\n\n### The family object\n\nAn object of the `WhichBrowser\\Model\\Family` class is used for the `family` property of the `WhichBrowser\\Model\\Browser` and `WhichBrowser\\Model\\Os` object and contains a number of properties. If a property is not applicable in this situation it will be null or undefined.\n\n**Properties:**\n\n* `name`  \n  a string containing the name of the family\n* `version`  \n  a version object containing information about the version of the family\n\n**Functions:**\n\n`getName()`  \nGet the name of the family\n\n`getVersion()`  \nGet the version of the family\n\n`toString()`  \nGet a human readable representation of the family\n\n\n### The using object\n\nAn object of the `WhichBrowser\\Model\\Using` class is used for the `using` property of the `WhichBrowser\\Model\\Browser` object and contains a number of properties. If a property is not applicable in this situation it will be null or undefined.\n\n**Properties:**\n\n* `name`  \n  a string containing the name of the webview\n* `version`  \n  a version object containing information about the version of the webview\n\n**Functions:**\n\n`getName()`  \nGet the name of the webview\n\n`getVersion()`  \nGet the version of the webview\n\n`toString()`  \nGet a human readable representation of the webview\n\n\n### The version object\n\nAn object of the `WhichBrowser\\Model\\Version` class is used for the `version` property of the `browser`, `engine` and `os` object and contains a number of properties and functions. If a property is not applicable in this situation it will be null or undefined.\n\n**Properties:**\n\n* `value`  \n  a string containing the original version number.\n* `alias`  \n  a string containing an alias for the version number, ie. 'XP' for Windows '5.1'.\n* `nickname`  \n  a string containing a nickname for the version number, ie. 'Mojave' for OS X '10.14'.\n* `details`  \n  an integer containing the number of digits of the version number that should be printed.\n\n**Functions:**\n\n`is($version)` or `is($comparison, $version)`  \nUsing this function it is easy to compare a version to another version. If you specify only one argument, this function will return if the versions are the same. You can also specify two arguments, in that case the first argument contains the comparison operator, such as `\u003c`, `\u003c=`, `=`, `=\u003e` or `\u003e`. The second argument is the version you want to compare it to. You can use versions like `10`, `10.7` or `'10.7.4'`, but be aware that `10` is not the same as `10.0`. For example if our OS version is `10.7.4`:\n\n```php\n$result-\u003eos-\u003eversion-\u003eis('10.7.4');\n// true\n\n$result-\u003eos-\u003eversion-\u003eis('10.7');\n// true\n\n$result-\u003eos-\u003eversion-\u003eis('10');\n// true\n\n$result-\u003eos-\u003eversion-\u003eis('10.0');\n// false\n\n$result-\u003eos-\u003eversion-\u003eis('\u003e', '10');\n// false\n\n$result-\u003eos-\u003eversion-\u003eis('\u003e', '10.7');\n// false\n\n$result-\u003eos-\u003eversion-\u003eis('\u003e', '10.7.3');\n// true\n```\n","funding_links":[],"categories":["PHP"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FWhichBrowser%2FParser-PHP","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FWhichBrowser%2FParser-PHP","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FWhichBrowser%2FParser-PHP/lists"}