PHPackages                             whichbrowser/server - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. whichbrowser/server

ActiveProject

whichbrowser/server
===================

Useragent sniffing server for Javascript

v2.0.13(4y ago)426.2k—0%15[1 PRs](https://github.com/WhichBrowser/Server/pulls)MITJavaScriptPHP &gt;=5.4.0

Since Nov 15Pushed 3y ago6 watchersCompare

[ Source](https://github.com/WhichBrowser/Server)[ Packagist](https://packagist.org/packages/whichbrowser/server)[ Docs](http://whichbrowser.net)[ RSS](/packages/whichbrowser-server/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (2)Versions (23)Used By (0)

[![](https://camo.githubusercontent.com/e408e57e783acd0c2f616f1a06328c40e9259dd934405e63a04ccb469337bbfe/68747470733a2f2f6170692e776869636862726f777365722e6e65742f776869636862726f777365722e737667)](https://camo.githubusercontent.com/e408e57e783acd0c2f616f1a06328c40e9259dd934405e63a04ccb469337bbfe/68747470733a2f2f6170692e776869636862726f777365722e6e65742f776869636862726f777365722e737667)

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

WhichBrowser/Server
===================

[](#whichbrowserserver)

This project sets up a server using WhichBrowser that exposes an API for browser detection that can be used by JavaScript in the browser. This project uses the [WhichBrowser/Parser-PHP](https://github.com/WhichBrowser/Parser-PHP) library for the actual useragent sniffing.

[![Build Status](https://camo.githubusercontent.com/cd15e014e00907d1b184be3a0a8c49aa73e99bbd2e5bc8df33ee1a89e04377e3/68747470733a2f2f7472617669732d63692e6f72672f576869636842726f777365722f5365727665722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/WhichBrowser/Server)[![License](https://camo.githubusercontent.com/605337f8207b9622e6c3c967cc9861c4a43a6b786baf766daed994f7eaa74a36/68747470733a2f2f706f7365722e707567782e6f72672f776869636862726f777365722f7365727665722f6c6963656e7365)](https://packagist.org/packages/whichbrowser/server)[![Latest Stable Version](https://camo.githubusercontent.com/48ce645abacd20c7d01037c5a7f4ff047af367d1d5082b4986894b72fd098a94/68747470733a2f2f706f7365722e707567782e6f72672f776869636862726f777365722f7365727665722f762f737461626c65)](https://packagist.org/packages/whichbrowser/server)

[![Twitter Follow](https://camo.githubusercontent.com/296d8494abd3f70bae4650cdbb37c1c1e5083653f620a40f9b3b459cc31c5c71/68747470733a2f2f696d672e736869656c64732e696f2f747769747465722f666f6c6c6f772f776869636862726f777365726c69622e7376673f7374796c653d736f6369616c)](https://twitter.com/whichbrowserlib)

Also available:

- [WhichBrowser/Parser-PHP](https://github.com/WhichBrowser/Parser-PHP)
    A PHP version of WhichBrowser for use on the server
- [WhichBrowser/Parser-JavaScript](https://github.com/WhichBrowser/Parser-JavaScript)
    A JavaScript version of WhichBrowser for use with Node.js on the server

---

Requirements
------------

[](#requirements)

The server should be able to handle PHP (5.4 or later) and included is a `.htaccess` file that instructs the server to use `detect.js` as an alias for `detect.php`. This is not required, but if your server does not support `.htaccess` files you may want to find a way to make your server do the same. Alternatively you could use the `detect.php` directly.

How to install it
-----------------

[](#how-to-install-it)

You can install WhichBrowser by using Composer - the standard package manager for PHP. The package is called `whichbrowser/server`. This sets up all dependancies like the PHP parser library. Go to an empty directory on your webserver, like the `www` or `public_html` directory of the domain where you want to install WhichBrowser.

```
composer create-project whichbrowser/server .

```

This will install the server in the current directory and install the `whichbrowser/parser` dependancy. You can easily update the parser library by running a simple command.

```
composer update

```

You should run this command as often as possible. You might even want to consider setting up a cron job for this purpose.

How to use it
-------------

[](#how-to-use-it)

The first step is to place a snippet of code on you webpage.

```

    (function(){var p=[],w=window,d=document,e=f=0;p.push('ua='+encodeURIComponent(navigator.userAgent));e|=w.ActiveXObject?1:0;e|=w.opera?2:0;e|=w.chrome?4:0;
    e|='getBoxObjectFor' in d || 'mozInnerScreenX' in w?8:0;e|=('WebKitCSSMatrix' in w||'WebKitPoint' in w||'webkitStorageInfo' in w||'webkitURL' in w)?16:0;
    e|=(e&16&&({}.toString).toString().indexOf("\n")===-1)?32:0;p.push('e='+e);f|='sandbox' in d.createElement('iframe')?1:0;f|='WebSocket' in w?2:0;
    f|=w.Worker?4:0;f|=w.applicationCache?8:0;f|=w.history && history.pushState?16:0;f|=d.documentElement.webkitRequestFullScreen?32:0;f|='FileReader' in w?64:0;
    p.push('f='+f);p.push('r='+Math.random().toString(36).substring(7));p.push('w='+screen.width);p.push('h='+screen.height);var s=d.createElement('script');
    s.src='//yourserver/whichbrowser/detect.js?' + p.join('&');d.getElementsByTagName('head')[0].appendChild(s);})();

```

Please make sure you change the URL of the detect.js file to point it to your own server.

To get the exact snippet you need to include visit the directory in which you installed WhichBrowser in your browser.

The second step is to create a new `WhichBrowser` object. This object will contain all the information the library could find about your browser.

For example:

```
result = new WhichBrowser();

```

The variable `result` now contains an object which you can query for information. There are various ways to access the information.

First of all, you can treat the object as a string to get a human readable identification:

```
"You are using " + result
// You are using Chrome 27 on Mac OS X 10.8.4

```

If you need to, you can also explicitly typecast the object to a string

```
String(result)
result.toString()

```

Or you can turn the object into JSON:

```
JSON.stringify(result)
// { "browser": {"name":"Chrome","version":{"value":"27"...

```

Another possiblity is to query the object:

```
result.isType('desktop')
// true

result.isType('mobile', 'tablet', 'media')
// false

result.isBrowser('Maxthon', '=', '5')
// false

result.isEngine('Blink')
// true

```

You can also access these properties directly:

```
result.browser
// Chrome 27

result.engine
// Blink

result.os
// Mac OS X 10.8.4

```

Or access parts of these properties directly:

```
result.browser.name
// Chrome

result.browser.name + ' ' + String(result.browser.version)
// Chrome 27

result.browser.version.major
// 27

result.browser.version.minor
// 0

result.browser.version.original
// 27.0.1453.110

result.engine.name
// Blink

```

Finally you can also query versions directly:

```
result.browser.version.is('>', 26)
// true

result.os.version.is('', '10')
// false

result.os.version.is('>', '10.7')
// false

result.os.version.is('>', '10.7.3')
// true

```

License
-------

[](#license)

Copyright (c) 2015 Niels Leenheer

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity35

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~111 days

Recently: every ~559 days

Total

22

Last Release

1498d ago

Major Versions

v1.0.1048 → v2.0.02015-11-30

### Community

Maintainers

![](https://www.gravatar.com/avatar/c047ed228e161add8594316eb5d3bceb15f46c18918176e96ee44883d1df57f0?d=identicon)[NielsLeenheer](/maintainers/NielsLeenheer)

---

Top Contributors

[![NielsLeenheer](https://avatars.githubusercontent.com/u/233230?v=4)](https://github.com/NielsLeenheer "NielsLeenheer (47 commits)")

---

Tags

javascriptphpserveruser-agentwhichbrowserbrowseruseragent

### Embed Badge

![Health badge](/badges/whichbrowser-server/health.svg)

```
[![Health](https://phpackages.com/badges/whichbrowser-server/health.svg)](https://phpackages.com/packages/whichbrowser-server)
```

###  Alternatives

[jenssegers/agent

Desktop/mobile user agent parser with support for Laravel, based on Mobiledetect

4.8k67.8M440](/packages/jenssegers-agent)[whichbrowser/parser

Useragent sniffing library for PHP

1.8k11.6M50](/packages/whichbrowser-parser)[donatj/phpuseragentparser

Lightning fast, minimalist PHP UserAgent string parser.

60417.1M60](/packages/donatj-phpuseragentparser)[foroco/php-browser-detection

Ultra fast PHP library to detect browser, OS, platform and device type by User-Agent parsing

1554.7M7](/packages/foroco-php-browser-detection)[thadafinser/user-agent-parser

UserAgent parsing done right http://useragent.mkf.solutions/

249316.9k2](/packages/thadafinser-user-agent-parser)[karmendra/laravel-agent-detector

Laravel wrapper for matomo-org/device-detector user agent parser

1241.6k](/packages/karmendra-laravel-agent-detector)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
