Coder Social home page Coder Social logo

whichbrowser / parser-php Goto Github PK

View Code? Open in Web Editor NEW
1.8K 1.8K 242.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%
library php user-agent whichbrowser

parser-php's Issues

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!

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.

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 =)

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

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.

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

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

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.

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.

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!

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

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

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.

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

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

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

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

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)

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

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.

Windows 10 edge

browser.os.version.alias

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

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?

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.

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

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.

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)

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!

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.