Coder Social home page Coder Social logo

whichbrowser / parser-php Goto Github PK

View Code? Open in Web Editor NEW
1.8K 79.0 243.0 10.98 MB

Browser sniffing gone too far — A useragent parser library for PHP

Home Page: http://whichbrowser.net

License: MIT License

PHP 100.00%
php whichbrowser user-agent library

parser-php's Introduction

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/Parser-PHP

The PHP version of WhichBrowser for use on a server. Fully compatible with PHP 7.0 or higher, including PHP 8.

Build Coverage Status License Latest Stable Version

Twitter Follow

Also available:


About WhichBrowser

But why almost completely useless and not completely useless? Well, 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.

Why is it extremely complicated?
Because 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.

What kind of information does it give? You 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:

JUC (Linux; U; 2.3.6; zh-cn; GT-I8150; 480*800) UCWEB8.7.4.225/145/800  
UC Browser 8.7 on a Samsung Galaxy W running Android 2.3.6

Android is never mentioned

Mozilla/5.0 (Series40; Nokia501/10.0.2; Profile/MIDP-2.1 Configuration/CLDC-1.1) Gecko/20100401 S40OviBrowser/3.0.0.0.73  
Nokia Xpress 3.0.0 on a Nokia Asha 501 running Nokia Asha Platform

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

Opera/9.80 (X11; Linux zvav; U; zh) Presto/2.8.119 Version/11.10  
Opera Mini on a Nokia 5230 running Series60 5.0

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

Requirements

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

How to install it

You can install WhichBrowser by using Composer - the standard package manager for PHP. The package is called whichbrowser/parser.

composer require whichbrowser/parser

You can easily update WhichBrowser by running a simple command.

composer update whichbrowser/parser

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

The first step require the Composer autoloader:

<?php

    require 'vendor/autoload.php';

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

For example:

$result = new WhichBrowser\Parser(getallheaders());

or:

$result = new WhichBrowser\Parser($_SERVER['HTTP_USER_AGENT']);

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 call to toString() function to get a human readable identification:

"You are using " . $result->toString();
// You are using Chrome 27 on OS X Mountain Lion 10.8

Another possiblity is to query the object:

$result->isType('desktop');
// true

$result->isType('mobile', 'tablet', 'media', 'gaming:portable');
// false

$result->isBrowser('Maxthon', '<', '4.0.5');
// false

$result->isOs('iOS', '>=', '8');
// false

$result->isOs('OS X');
// true

$result->isEngine('Blink');
// true

You can also access these properties directly:

$result->browser->toString();
// Chrome 27  

$result->engine->toString();
// Blink

$result->os->toString();
// OS X Mountain Lion 10.8

Or access parts of these properties directly:

$result->browser->name;
// Chrome

$result->browser->name . ' ' . $result->browser->version->toString();
// Chrome 27

$result->browser->version->value;
// 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.7.4');
// false

Options

It is possible to set additional options by passing an array as the second parameter when creating the Parser object.

Disabling detection of bots

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

$result = new WhichBrowser\Parser(getallheaders(), [ 'detectBots' => false ]);

Enable result caching

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

There 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. For a list of other packages that provide adapters see Packagist.

For example, if you want to enable a memcached based cache you need to install an extra composer package:

composer require cache/memcached-adapter

And change the call to WhichBrowser/Parser as follows:

$client = new \Memcached();
$client->addServer('localhost', 11211);

$pool = new \Cache\Adapter\Memcached\MemcachedCachePool($client);

$result = new WhichBrowser\Parser(getallheaders(), [ 'cache' => $pool ]);

or

$client = new \Memcached();
$client->addServer('localhost', 11211);

$pool = new \Cache\Adapter\Memcached\MemcachedCachePool($client);

$result = new WhichBrowser\Parser();
$result->setCache($pool);
$result->analyse(getallheaders());

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

API reference

The Parser object

After a new WhichBrowser\Parser object is created, it contains a number of properties and functions. All of these properties are guaranteed to be present.

Properties:

  • browser
    an object that contains information about the browser itself
  • engine
    an object that contains information about the rendering engine
  • os
    an object that contains information about the operating system
  • device
    an object that contains information about the device

Functions:

getType()
Returns 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.

isType($type [,$type [,$type [,$type]]])
If 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

isMobile()
Return 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.

isBrowser($name [, $comparison, $version])
Is 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 <, <=, =, => or >. 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.

isEngine($name [, $comparison, $version])
Is used to query the name and version property of the engine object. This function works in exactly the same way as isBrowser.

isOs($name [, $comparison, $version])
Is used to query the name and version property of the os object. This function works in exactly the same way as isBrowser.

isDetected()
Is there actually some browser detected, or did we fail to detect anything?

toString()
Get a human readable representation of the detected browser, including operating system and device information.

The browser object

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

Properties:

  • name
    a string containing the name of the browser
  • alias
    a string containing an alternative name of the browser
  • version
    a version object containing information about the version of the browser
  • stock
    a boolean, true if the browser is the default browser of the operating system, false otherwise
  • channel
    a string containing the distribution channel, ie. 'Nightly' or 'Next'.
  • mode
    a string that can contain the operating mode of the browser, ie. 'proxy'.
  • hidden
    a boolean that is true if the browser does not have a name and is the default of the operating system.
  • family
    an object that contains information about to which family this browser belongs
  • using
    an object that contains information about to which kind of webview this browser uses

Functions:

isFamily($name)
Does the family of this browser have this name, or does the browser itself have this name.

isUsing($name)
Is the browser using a webview using with the provided name.

getName()
Get the name of the browser

getVersion()
Get the version of the browser

toString()
Get a human readable representation of the detected browser

The engine object

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

Properties:

  • name
    a string containing the name of the rendering engine
  • version
    a version object containing information about the version of the rendering engine

Functions:

getName()
Get the name of the rendering engine

getVersion()
Get the version of the rendering engine

toString()
Get a human readable representation of the detected rendering engine

The os object

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

Properties:

  • name
    a string containing the name of the operating system
  • version
    a version object containing information about the version of the operating system
  • family
    an object that contains information about to which family this operating system belongs

Functions:

isFamily($name)
Does the family of this operating system have this name, or does the operating system itself have this name.

getName()
Get the name of the operating system

getVersion()
Get the version of the operating system

toString()
Get a human readable representation of the detected operating system

The device object

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

Properties:

  • type
    a string containing the type of the browser.
  • subtype
    a string containing the subtype of the browser.
  • identified
    a boolean that is true if the device has been positively identified.
  • manufacturer
    a string containing the manufacturer of the device, ie. 'Apple' or 'Samsung'.
  • model
    as string containing the model of the device, ie. 'iPhone' or 'Galaxy S4'.

The type property can contain any value from the following list:

  • desktop
  • mobile
  • pda
  • dect
  • tablet
  • gaming
  • ereader
  • media
  • headset
  • watch
  • emulator
  • television
  • monitor
  • camera
  • printer
  • signage
  • whiteboard
  • devboard
  • inflight
  • appliance
  • gps
  • car
  • pos
  • bot
  • projector

If the type is "mobile", the subtype property can contain any value from the following list:

  • feature
  • smart

If the type is "gaming", the subtype property can contain any value from the following list:

  • console
  • portable

Functions:

getManufacturer()
Get the name of the manufacturer

getModel()
Get the name of the model

toString()
Get a human readable representation of the detected device

The family object

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

Properties:

  • name
    a string containing the name of the family
  • version
    a version object containing information about the version of the family

Functions:

getName()
Get the name of the family

getVersion()
Get the version of the family

toString()
Get a human readable representation of the family

The using object

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

Properties:

  • name
    a string containing the name of the webview
  • version
    a version object containing information about the version of the webview

Functions:

getName()
Get the name of the webview

getVersion()
Get the version of the webview

toString()
Get a human readable representation of the webview

The version object

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

Properties:

  • value
    a string containing the original version number.
  • alias
    a string containing an alias for the version number, ie. 'XP' for Windows '5.1'.
  • nickname
    a string containing a nickname for the version number, ie. 'Mojave' for OS X '10.14'.
  • details
    an integer containing the number of digits of the version number that should be printed.

Functions:

is($version) or is($comparison, $version)
Using 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 <, <=, =, => or >. 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:

$result->os->version->is('10.7.4');
// true

$result->os->version->is('10.7');
// true

$result->os->version->is('10');
// true

$result->os->version->is('10.0');
// false

$result->os->version->is('>', '10');
// false

$result->os->version->is('>', '10.7');
// false

$result->os->version->is('>', '10.7.3');
// true

parser-php's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

parser-php's Issues

No vendor/autoload.php file

Hi,
I havn't found the file'vendor/autoload.php'.
Did you update this project?
Can you update the home page?
Thanks.

Edge version

I noticed MS Edge is detected without a version number but other browsers are detected with their version numbers.

Based on the recent MS blog guidance Edge should be detected as Edge 12. See other tools like caniuse or es6-compat tables.

![image](https://cloud.githubusercontent.com/assets/4303/10008459/a250842c-6083-11e5-9118-ba281ca52add.png) ![image](https://cloud.githubusercontent.com/assets/4303/10008464/b09bf548-6083-11e5-8c52-b444d320a6aa.png)

Browser->Name Not working

Every time I write code like so:

$user = new WhichBrowser($agents);
$user->analyseUserAgent($agents['ua']);
$browser = $user->browser->name;

where agents is an array of Agent Strings, I get an error that reads:

Notice: Undefined property: stdClass::$name in.....

and I was hoping someone could help me out, because it does the same thing for when I try to get the version of the browser or the OS. Really the only thing that works is when I analyse the device so please help, thank you!

Despite setting MIME-Type, client still interprets detect.js as JS

Even with the .htaccess file, my browser still has an issue with interpreting detect.js correctly.
In the console I get the error:

Resource interpreted as Script but transferred with MIME type application/x-httpd-php: "http://(my server)/WhichBrowser/detect.js?ua=Mozilla%2F5.0%20(Macinto…e%2F33.0.1750.117%20Safari%2F537.36&e=52&f=127&r=x0c686ywrk9&w=1920&h=1080". 

This is followed by the error:

Uncaught SyntaxError: Unexpected token <     detect.js

, which I presume is because the browser did not interpret detect.js correctly.

This is akin to what @acidking mentioned in #9 . I toggled all 4 permutations of FastCGI/CGI and PHP 5.3/5.4 on the server to no avail.

Curling the example server with:

curl -I "http://api.whichbrowser.net/dev/detect.js?ua=Mozilla%2F5.0%20(Macintosh%3B%20Intel%20Mac%20OS%20X%2010_8_5)%20AppleWebKit%2F537.36%20(KHTML%2C%20like%20Gecko)%20Chrome%2F33.0.1750.117%20Safari%2F537.36&amp;e=52&amp;f=127&amp;r=tlvif4m42t9&amp;w=1920&amp;h=1080"

returns Content-Type of text/javascript when my own server reports application/x-httpd-php with the same request.

Chrome 33.0, OS X 10.8.5
Same result on Firefox 27.0.1
Apache 2.2.22-14

error when calling toJSON function

Sometime the OS version in the object is found to be null and calling to toJSON on it causes an error.

Specifically in places where this.version.toJSON() is used without checking if this.version is null or not.

Include Parser / Testrunner / Server / ...as a composer dependency here

Its seems that the splitted packages are currently just a copy out from this main repo.

Currently the Testrunner cannot be autoloaded and the filenames are still lowercase, which prevents from installing correctly. ( i had a PR, but then noticed it's corrected here partly already)
https://github.com/WhichBrowser/Testrunner

I think correct would be to develop the Testrunner at the Testrunner repo and include it here as composer dependency. Or another way would be a git submodule.

But having just a copy of the sources will always lead to differences.

What do you think?

Error with the library

Hello,

I have this problem when I call the library with the file "detect.js" and I don't konw why...

Parse error: syntax error, unexpected T_STATIC, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in myserver/WhichBrowser/libraries/whichbrowser.php on line 4639

This line 4639 is "static $ANDROID_BROWSERS = array();"

UPDATE : This is the screen, the problem is from "whichbrowser.php" : http://pbrd.co/1kndtuj
But I think it's before the line 4639 because if delete this Class, I still have this message...

Can you help me ?
Regards.

Readme example actually mentions Android

JUC (Linux; U; 2.3.6; zh-cn; GT-I8150; 480_800) UCWEB8.7.4.225/145/800
UC Browser 8.7 on a Samsung Galaxy W running _Android* 2.3.6

Android is never mentioned

In fact it is =) I know its not the point, but you might want to put a better example out there =)

Strict standards error.

Getting this error on php 5.5

<br />
<b>Strict Standards</b>:  Only variables should be passed by reference in <b>.../libraries/whichbrowser.php</b> on line <b>3326</b><br />

Windows 10 edge

browser.os.version.alias

doesn't seem to be filled in on windows 10 on edge browser.

How can I install this without Composer?

Composer isn't available to me and our ITS department won't install it. I've uploaded all the files to the server but I don't know which ones to include in my script.
Thanks!

Invalid key while using cache/filesystem-adapter

Fatal error: Uncaught exception 'Cache\Adapter\Common\Exception\InvalidArgumentException' with message 'Invalid key "whichbrowser-bf04fa69261304bdef02d3c56194ef91". Valid keys must match [a-zA-Z0-9_.! ].' in vendor/cache/filesystem-adapter/FilesystemCachePool.php:122

Fix: Remove/replace '-' at line 93 of vendor/whichbrowser/parser/src/Cache.php

iOS 8.X not recognized

I think the recognition of iOS minor-Versions is messed up. The Useragent of iOS-devices (Version 8.1) is something like:

Mozilla/5.0 (iPhone; CPU iPhone OS 8_1 like Mac OS X) AppleWebKit/600.1.3 (KHTML, like Gecko) Version/8.0 Mobile/12A4345d Safari/600.1.4

Now whichbrowser is looking for /Version/([0-9.]+)/u, however it should be looking for something like /OS ([0-9_]+)/u to get the real Version as the 'Version-Version' is not changing. I did this in line 3928 of the newest whichbrowser-version and it worked for me.

(unfortunately I have no time to make a pull request (and I'm pretty new to gitHub^^). I hope this spares you some time though)

Browser.browser.name is null on Android 4.1.2, while String(browser) has proper resolution.

This is what I'm using:

(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='js/detect.js?' + p.join('&');d.getElementsByTagName('head')[0].appendChild(s);
})();

(function init() {
    "use strict";
    if (typeof window.WhichBrowser === 'undefined') {
        return setTimeout(init, 10);
    }
    var ua = new WhichBrowser();
    alert(String(ua)); // Sony Xperia Go running Android 4.1.2
    alert(ua.browser.name); // null
    alert(ua.browser); // empty string

})();

Windows Surface identified as Desktop and Windows 8 OS

Thanks for the code, it's a quite useful tool.
Is there a way to identify the Windows Surface tablet? It returns as Desktop device and OS Windows 8. Would be good if at least can be identified as tablet and something other than desktop.

Add composer support

Would you consider adding a composer.json file for using the library in composer based projects? It would be very helpful for upgrading. Thanks!

Undefined property: stdClass::$name in whichbrowser.php

Niels

I've been getting ALOT of errors in whichbrowser.php on lines 170 and 190 :

if ($this->browser->name == 'Safari') {

and

if ($this->browser->name == 'Chrome') {

To get around this i've simply wrapped them both with :

if (isset($this->browser->name)) {

Cheers

Ged.

Correct name for Windows Phone 10 is actually Windows 10 Mobile

While, the operating system is still called Windows Phone 10 in the user agent string, the marketing name is Windows 10 Mobile. I think we should change this, but if possible it should not interfere.

toString() should not be Windows Phone 10
toString() should be Windows 10 Mobile

isOs('Windows Phone') should still be true.
isOs('Windows') should still be false.

Adding "Windows" as alias to the Os object will get us halfway there. This will not interfere with the is functions and will not cause the name property to change.

In order to achieve the monicer Windows 10 Mobile we should introduce an new property on the Os object called edition or variant. This should be postfixed to the output of toString().

Android is wrongly detected as OS when Jquery ajax call is used

As BrowserId will always detect an Android OS each time X-Requested-With header is sent,
we have false positive result when we have a JQuery ajax call.

Indeed, ajax call will sent same header with XMLHttRequest value.

BrowserId should make an exception for this header value.
and some more tests are needed to understand what happens when a JQuery ajax call is made from an Android device.

Thanks

Google Page Speed Insights User Agents

The UA's used by Google Page Speed Insights analysis are correctly detected as bots,
but the device type is not being set

Desktop
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko; Google Page Speed Insights) Chrome/27.0.1453 Safari/537.36

Mobile
Mozilla/5.0 (iPhone; CPU iPhone OS 6_0_1 like Mac OS X) AppleWebKit/537.36 (KHTML, like Gecko; Google Page Speed Insights) Version/6.0 Mobile/10A525 Safari/8536.25

apache_request_headers:This function is only supported when PHP is installed as an Apache module.

After a quick search I found that code at stackoverflow

if( !function_exists('apache_request_headers') ) {
///
function apache_request_headers() {
$arh = array();
$rx_http = '/\AHTTP_/';
foreach($SERVER as $key => $val) {
if( preg_match($rx_http, $key) ) {
$arh_key = preg_replace($rx_http, '', $key);
$rx_matches = array();
// do some nasty string manipulations to restore the original letter case
// this should work in most cases
$rx_matches = explode('
', $arh_key);
if( count($rx_matches) > 0 and strlen($arh_key) > 2 ) {
foreach($rx_matches as $ak_key => $ak_val) $rx_matches[$ak_key] = ucfirst($ak_val);
$arh_key = implode('-', $rx_matches);
}
$arh[$arh_key] = $val;
}
}
return( $arh );
}
///
}
///

added this to whichbrowser.php and it worked out for me....

browser detected is not work in iOS device

// iPhone 4
$user_agent = 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_2_1 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8C148 Safari/6533.18.5';
// iPhone 5
$user_agent = 'Mozilla/5.0 (iPhone; CPU iPhone OS 7_0 like Mac OS X; en-us) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/11A465 Safari/9537.53';
// iPhone 6
// $user_agent = 'Mozilla/5.0 (iPhone; CPU iPhone OS 8_0 like Mac OS X) AppleWebKit/600.1.3 (KHTML, like Gecko) Version/8.0 Mobile/12A4345d Safari/600.1.4';
// iPhone 6 Plus
// $user_agent = 'Mozilla/5.0 (iPhone; CPU iPhone OS 8_0 like Mac OS X) AppleWebKit/600.1.3 (KHTML, like Gecko) Version/8.0 Mobile/12A4345d Safari/600.1.4';
// iPad mini
$user_agent = 'Mozilla/5.0 (iPad; CPU OS 7_0_4 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/11B554a Safari/9537.53';

echo $result->browser->toString();
// is empty, expect Safari

these all user_agent is from PC Chrome Developer Tools.

No issue here

I have no issue. I just wanted to tell you this stuff is awesome!

(This may not be the proper channel for thanks but my brain is currently slightly fried and I can't think of another).

Also, did you know the quote from House M.D. could also be attributed to Mark Twain?

"Everybody lies...every day, every hour, awake, asleep, in his dreams, in his joy, in his mourning.
If he keeps his tongue still his hands, his feet, his eyes, his attitude will convey deception."

Chrome Unstable is identified as Chrome Nightly

I am currently running the chrome unstable channel.

My browser is identified by: Chrome Nightly 31.0.1636.0,
however with about:version it gives: Version 31.0.1636.0 dev
on http://www.chromium.org/getting-involved/dev-channel it speaks about dev-channel,
and when talking about the executable, it is more like chrome unstable
(http://www.ubuntuupdates.org/package/google_chrome/stable/main/base/google-chrome-unstable)

So I would expect something like Chrome Dev 31.0.xxx or Chrome Unstable 31.0.xxx instead of Chrome Nightly 31.0.xxx
especially since this channel is not updated every night

OS X 10.10.2

Although the OS version is presented in the user agent string as “Macintosh; Intel Mac OS X 10_10_2” html5test still records it as “OS X Yosemite 10.10”.

Sony eReader is just "Linux"

I have a Sony PRS T2 e-reader. Going to whichbrower.net shows me:

You are using Linux
Mozilla/5.0 (Linux; U; en-us; EBRD1201; EXT) AppleWebKit/533.1 (KHTML,
like Gecko) Version/4.0 Mobile Safari/533.1

why do you need php, npm support

Without looking at the source, my first thought going over the Readme is why do you need php? Could you not come up with a Javascript solution that doesn't have a dependency on php? This would be really nice to have as straight javascript then it could just run with only the inclusion of a js file.
Also i'm not sure how to use bower, but i am familiar with npm, it would be convenient if you could do a class npm install whichbrowser like many other modules. Which is i believe node support. This can probably just be marked as a question.

Device name on Firefox Mobile

Hey man and thanks for your awesome project. I have problem in getting user device name where use Firefox Pc or Firefox for Android but the device name does appear with chrome opera and ucweb for Android. Here's a link to the example, http://www.arrowtxt.in/dex.
I hope it can be fixed ASAP. Thanks again for your tool.

Node.js port?

Hey Niels, your library looks pretty precious :-)

Have you ever had requests for porting it to Node.js? We might be interested in doing that... In the Node world there's platform.js which is nice, but WhichBrowser seems even more powerful (despite the fact it lacks unit testing, whereas platform.js doesn't).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.