whichbrowser / parser-php Goto Github PK
View Code? Open in Web Editor NEWBrowser sniffing gone too far — A useragent parser library for PHP
Home Page: http://whichbrowser.net
License: MIT License
Browser sniffing gone too far — A useragent parser library for PHP
Home Page: http://whichbrowser.net
License: MIT License
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!
Project Spartan is using Edge 12.0 in the agent string.
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.
The UA of Desktop UCBrowser is UBrowser but WhichBrowser detects it as Mobile UCBrowser which is with UA of UCBrowser. The Desktop UCBrowser is available at http://pc.uc.cn (Chinese version) or http://pc.ucweb.com (Internationalization version).
Hello!
Could you please also consider to refactor your code according to community-accepted PSR standards?
I installed the files on my server and using the test tool, the return is always below this.
http://www.rendawbs.com/fb/whichbrowser/tools/
{
browser: {"stock":true,"hidden":false,"channel":"","mode":""}
engine: {}
os: {}
device: {"type":"","identified":0}
}
I tried several different UA and always equal
Mozilla/5.0 (Windows NT 6.1; rv:28.0) Gecko/20100101 Firefox/28.0
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 =)
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
Given the user agent of "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:37.0) Servo/1.0 Firefox/37.0", Firefox 37 is detected rather than Servo.
// 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.
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&e=52&f=127&r=tlvif4m42t9&w=1920&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
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 />
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.
PHP Notice: Undefined offset: 3 in /var/www/lib/WhichBrowser/src/Analyser/Header/Wap.php on line 38
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.
Hi,
would it be possible, to create a new method isMobile()
?
Currently we got this implemented here, but such vendor specific code is always dangerous (since it can change) and if it's a internal method, you will know when you add a new type to change it also.
https://github.com/ThaDafinser/UserAgentParser/blob/master/src/Provider/WhichBrowser.php#L203
Installed the latest binary and it shows 32 version but not 33.
I access http://whichbrowser.net via smartphone Xiaomi Redmi Note 3 in Firefox, it displays "You are using Firefox Mobile 47.0 on Android 5.1.1".
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!
Hi! Thanks for the hard work!
However, I'm not sure how am I supposed to add this library to my project. It's not listed with both Bower and Packagist / Composer.
Please advise, thanks!
http://omahaproxy.appspot.com/all.json is available if you want a data feed that's maintained for what is the stable version of Chrome etc.
more human readable version here https://googledrive.com/host/0B8R1QvA3x5IbWll3M0hIYXVLZlk/
dunno if this is useful to you.. but just FYI
You'll have fun with this one.
https://gist.github.com/jacobrossi/c9699b27df2f4e97c0bd
Mozilla/5.0 (Windows NT 6.4; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.143 Safari/537.36 Edge/12.0
(Source from gabceb/jquery-browser-plugin#47)
This UA could break a lot of stuff if it stays in this form (and I'm sure it will).
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”.
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
it seems that this should be detected as mobile, but currently it shows desktop
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()
.
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.
Hi,
I just discover that Browsers.browser.version is null on Safari iOS. its the same for:
It is a bug or not ?
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).
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
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."
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....
I was running tests and I noticed that the Surface 3 running Edge will be identified as 'Android'.
The user agent string is as follow:
Mozilla/5.0 (Windows NT 10.0; WOW64; rv:47.0) Gecko/20100101 Firefox/47.0
Environment:
Steps:
You are using Internet Explorer 8.0 on Windows 7
. Wrong browser version and wrong os version.Answered my own question :)
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) |
imitates, is that a bug or a feature?
this comes up when actually using Opera 12 on WinXP SP3 and Win7 64bit.
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
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.
browser.os.version.alias
doesn't seem to be filled in on windows 10 on edge browser.
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?
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
})();
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.
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
Hi,
I havn't found the file'vendor/autoload.php'.
Did you update this project?
Can you update the home page?
Thanks.
This is a UA of a HP tablet in our company.
Dunno how the others detect it as tablet, but i guess based on the Touch
string
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)
Is there some reason that it doesn't detect the correct version of Firefox? Thanks.
Would you consider adding a composer.json file for using the library in composer based projects? It would be very helpful for upgrading. Thanks!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.