{"id":19388986,"url":"https://github.com/james2doyle/browser-sniffer","last_synced_at":"2026-05-15T17:07:41.500Z","repository":{"id":36114269,"uuid":"40416509","full_name":"james2doyle/browser-sniffer","owner":"james2doyle","description":"A simple class to detect the browser and the platform (operating system) that the user is using","archived":false,"fork":false,"pushed_at":"2015-08-09T18:35:26.000Z","size":136,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-03T20:04:20.335Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/james2doyle.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-08-08T21:09:13.000Z","updated_at":"2016-10-26T16:14:55.000Z","dependencies_parsed_at":"2022-09-24T19:21:14.664Z","dependency_job_id":null,"html_url":"https://github.com/james2doyle/browser-sniffer","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/james2doyle/browser-sniffer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/james2doyle%2Fbrowser-sniffer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/james2doyle%2Fbrowser-sniffer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/james2doyle%2Fbrowser-sniffer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/james2doyle%2Fbrowser-sniffer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/james2doyle","download_url":"https://codeload.github.com/james2doyle/browser-sniffer/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/james2doyle%2Fbrowser-sniffer/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33072994,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-15T11:35:32.926Z","status":"ssl_error","status_checked_at":"2026-05-15T11:35:31.362Z","response_time":103,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":[],"created_at":"2024-11-10T10:14:17.077Z","updated_at":"2026-05-15T17:07:41.468Z","avatar_url":"https://github.com/james2doyle.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Browser Sniffer Class\n=====================\n\nA very simple class that takes in a user agent string and returns the browser name (Firefox, Chrome, Opera, etc.) and also the Operating System (Mac, Windows, Android, etc.).\n\n### Install\n\nIt is recommended that you install the PHP Browser library [through composer](http://getcomposer.org/). To do so, add the following lines to your `composer.json` file.\n\n```json\n{\n    \"require\": {\n        \"james2doyle/browser-sniffer\": \"dev-master\"\n    }\n}\n```\n\n### Reasons\n\nFirstly, you *should not* use browser sniffing for feature detection, [use Modernizr](http://modernizr.com/).\n\nWe mainly use this for style tweaks between different browsers, or sometimes you may need to add a little script (differences in keystroke handling can be difficult to feature detect) or tweak on a specific platform combination and so you might do a check to see if that makes sense.\n\nThe results are pretty crude. We only return `internet-explorer` if IE is found. There is *no version information*.\n\nFor the platform, we only return that operation system. This means all iOS devices (iPad, iPhone, iPod) would only return `ios`. If you need to know specifics about the device, [use media queries](http://stephen.io/mediaqueries/).\n\n### Results\n\nThe information returned is all *class* safe. This package should primarily be used to add additional classes to the `\u003cbody\u003e` or `\u003chtml\u003e` tag of a template. That is the reason is was made.\n\n### Support\n\n**Platforms**\n\n* Linux\n* IOS\n* Mac\n* Windows\n* Windows Phone\n* Android\n* Blackberry\n\n**Browsers**\n\n* MSIE\n* Trident\n* Edge\n* Vivaldi\n* Firefox\n* Chrome\n* Opera\n* Opera Mini\n* Safari\n\n### Usage\n\n```php\n\u003c?php\n$browser = new Browser($_SERVER['HTTP_USER_AGENT']);\n?\u003e\n\u003c!DOCTYPE html\u003e\n\u003chtml\u003e\n\u003chead\u003e\n  \u003cmeta charset=\"UTF-8\"\u003e\n  \u003ctitle\u003eBrowser Class\u003c/title\u003e\n  \u003cstyle type=\"text/css\" media=\"screen\"\u003e\n    body.google-chrome.mac {\n      background: red;\n    }\n  \u003c/style\u003e\n\u003c/head\u003e\n\u003cbody class=\"\u003c?php echo $browser-\u003efullClass() ?\u003e\"\u003e\n  \u003cdiv class=\"content\"\u003e\n    \u003cp\u003e\u003c?php echo $browser-\u003egetBrowser().' '.$browser-\u003egetPlatform() ?\u003e\u003c/p\u003e\n    \u003cpre\u003e\u003c?php var_dump($browser-\u003egetResults()); ?\u003e\u003c/pre\u003e\n  \u003c/div\u003e\n\u003c/body\u003e\n\u003c/html\u003e\n```\n\nResults for *Chrome on a Macbook*:\n\n```html\n\u003c!DOCTYPE html\u003e\n\u003chtml\u003e\n\u003chead\u003e\n  \u003cmeta charset=\"UTF-8\"\u003e\n  \u003ctitle\u003eBrowser Class\u003c/title\u003e\n  \u003cstyle type=\"text/css\" media=\"screen\"\u003e\n    body.google-chrome.mac {\n      background: red;\n    }\n  \u003c/style\u003e\n\u003c/head\u003e\n\u003cbody class=\"google-chrome mac\"\u003e\n  \u003cdiv class=\"content\"\u003e\n    \u003cp\u003egoogle-chrome mac\u003c/p\u003e\n    \u003cpre\u003earray(3) {\n      [\"ua\"]=\u003e\n      string(120) \"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.35 Safari/537.36\"\n      [\"platform\"]=\u003e\n      string(3) \"mac\"\n      [\"browser\"]=\u003e\n      string(13) \"google-chrome\"\n    }\u003c/pre\u003e\n  \u003c/div\u003e\n\u003c/body\u003e\n\u003c/html\u003e\n```\n\nThis page would only have a red background is someone was looking at the page using a Mac (desktop or laptop) with Google Chrome.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjames2doyle%2Fbrowser-sniffer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjames2doyle%2Fbrowser-sniffer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjames2doyle%2Fbrowser-sniffer/lists"}