ua-parser / uap-php Goto Github PK
View Code? Open in Web Editor NEWPHP implementation of ua-parser
License: Other
PHP implementation of ua-parser
License: Other
This package registers ua-parser.php
as bin file, and the file mode is executable. However when actually making use of this (composer global require ua-parser/uap-pphp
), invoking it doesn't work because there is no hashbang.
Either add a shebang (and maybe rename the file to without a .php
extension), or remove it from the bin
list in composer.json
.
Right now the only way to invoke it is by doing something like php
which uaparser.php ua-parser:parse 'string'
.
Trying to figure out the role of the thing in uap-python I looked it up, and apparently it was deprecated back then and removed in ua-parser/uap-core#58 by (and at the instigation of) the uap-clj maintainer.
Hello,
Great plugin!
What is the minimum PHP version required to run this plugin?
Thanks,
There would be noticeably faster parsing when the browsers and operating systems which have the most market share are placed on top of the regexes list. Due to looping through the list, the more chances we have a match the sooner we break the loop and return the result.
This issue also applies to other languages and, thus, is not limited to PHP only. Perhaps this is not the right place to create this issue, but you can move it to the proper repository.
Hello,
sadly i currently have a conflict with another package, with the same namespace:
https://github.com/ua-parser/uap-php/blob/master/composer.json#L26
https://github.com/yzalis/UAParser/blob/master/composer.json#L24
It is possible to add a vendor Namespace?
Folling user agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.10240
is incorrectly identified as Chrome. Should be identified as Edge.
While using your project - which is very cool, thank you :) - I am facing a small issue:
$parser = \UAParser\Parser::create();
$result = $parser->parse($useragent_string);
When I am using this two lines, Visual Studio Code is complaining about the function "parse" as AbstractParser does not have any function "parse". Because function "create" returns this kind of object, VS Code is correct at this point I guess.
Image of the issue hint:
The last update of resources was done almost 1 year. uap-core has seen a bunch of activity in the meantime. It would be great to bring them in the composer package.
Here is my PHP code based off of the sample usage code:
require_once($CFG->dirroot.'/vendor/autoload.php');
$ua = $_SERVER['HTTP_USER_AGENT'];
$parser = UAParser\Parser::create();
$result = $parser->parse($ua);
But I'm getting the following error message. Has anyone seen the same message before or know what the issue could be?
Warning: preg_match(): Unknown modifier 'T' in /vagrant/moodle/vendor/ua-parser/uap-php/src/AbstractParser.php on line 83
Call Stack
# Time Memory Function Location
1 0.0000 236840 {main}( ) ../index.php:0
2 0.1604 11097280 create_help_message( ) ../index.php:147
3 0.1635 12078336 UAParser\Parser->parse( ) ../help_lib.php:349
4 0.1653 12097032 UAParser\DeviceParser->parseDevice( ) ../Parser.php:51
5 0.1654 12099768 UAParser\AbstractParser->tryMatch( ) ../DeviceParser.php:26
6 0.1656 12158752 preg_match ( ) ../AbstractParser.php:83
Chrome Beta on Xiaomi Mi 4i has the following user agent string:
Mozilla/5.0 (Linux; Android 5.0.2; Mi 4i Build/LRX22G) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.36 Mobile Safari/537.36
Installing the default version with composer (require ua-parser/uap-php
) identifies device brand as Generic_Android
, where it should be XiaoMi
Editing https://github.com/ua-parser/uap-php/blob/master/resources/regexes.php#L4451 , changing it to 'regex' => '; *((Mi|MI|HM|MI-ONE|Redmi)[ -](NOTE |Note )?[^;/]*) Build/',
(adding Mi
) makes it detect the brand correctly
Some of our users are running IE11 in "compatibility mode". It would be nice to be able to detect this. UAParser just shows them as running IE7.
Consider these two user agent strings.
1 - Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.86 Safari/537.36 OPR/33.0.1990.115
2 - Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.86 Safari/537.36
As you can see in browsers versions there is a 4th number marking "patch minor".
This 4th number is more and more common in modern devices and I think you should add support for it.
Changing regex (for Opera string )from this:
'regex' => '(?:Chrome).*(OPR)/(\d+).(\d+).(\d+)'
to this:
'regex' => '(?:Chrome).*(OPR)/(\d+).(\d+).(\d+)(?:.(\d+))?'
did not help.
I think you should add some code support for this.
Thank you.
Is there anyway for uap-php to tell the difference between WebView in an Android App and the Chrome Mobile browser. https://developer.chrome.com/multidevice/user-agent
Looks like if it has a Version/x.x then it is webview ie..
Mozilla/5.0 (Linux; Android 4.4.4; SAMSUNG-SM-G870A Build/KTU84P) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/33.0.0.0 Mobile Safari/537.36
Vs a real chrome ua like this one:
Mozilla/5.0 (Linux; Android 4.4.4; SAMSUNG-SM-G900A Build/KTU84P) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.96 Mobile Safari/537.36
Are there any plans for adding compatibilty with PHP 8.0?
Would you like me to create a pull request for this?
ua-parser/uap-php
can't be installed in a Symfony 3 project because it uses some components from Symfony 2, without explicit support to version 3.
Your requirements could not be resolved to an installable set of packages.
ua-parser/uap-php v3.4.0 requires symfony/finder ~2 -> satisfiable by symfony/finder[2.0.4, 2.0.5, ...]
[...]
- don't install symfony/finder v2.7.7|don't install symfony/symfony v3.0.0
- don't install symfony/finder v2.8.0|don't install symfony/symfony v3.0.0
- Installation request for symfony/symfony 3.0.* -> satisfiable by symfony/symfony[v3.0.0].
- Installation request for ua-parser/uap-php ~3.4 -> satisfiable by ua-parser/uap-php[v3.4.0, v3.4.1, v3.4.2, v3.4.3, v3.4.4].
The same conflict would happen with the other components (yaml
, filesystem
and console
).
The last automatic update of the uap-core submodule was 2 years ago.
It would be great if those updates could be re-enabled and released regularly.
We use this package in another package, and I would have sworn that $client->device->family
would return Tablet
for an iPad
or Mobile
for an iPhone
, but now we get iPhone
for an 'iPhone
From what we remember, $client->device->family
had 3 buckets...
Did something change in a newer version or did we just have it wrong to begin with?
Thanks.
I know this is a fairly obscure choice, but I've got all my clients into SRWare Iron (Portable). It's being recognized as Chrome. The two most recent versions (51.x and 52.x, the current one) have changed how their ua string is formatted.
Here's my current one:
Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2750.0 Iron Safari/537.36
There is no longer a slash and a version number after "Iron" in the string.
I'm not sure where to post this concern, so I'm starting here. Long time happy user, first time troubleshooter. Thanks for any advice and for the fabulous tool.
i need a tag in order for this Pr to work nelmio/NelmioSecurityBundle#165
Hi,
The option to convert from yaml to json is not implemented as stated. Actually it does read the yaml file and writes to a PHP file named 'resources.php'.
Also it will be nice to have option to specify the destination file.
Cheers,
Jai
At the moment there is no regexp.php
file in the composer package thus it does not work right out of the box. If someone uses a package that depends on ua-parser/ua-parser
he must know too much about package's internals.
I suggest to add regexp.php
to the composer's package.
Am I the only one that struggle to install ua-parser with composer:
Loading composer repositories with package information
Updating dependencies (including require-dev)
- Installing ua-parser/uap-php (dev-master 1ff0c92)
Cloning 1ff0c92eca7958d3977480cf5c1a15b31b7ca909
[ErrorException]
file_put_contents(/Volumes/Default/server/sy_admin/api/composer/vendor/bin/uaparser.php): failed to open stream: No such file or directory
update [--prefer-source] [--prefer-dist] [--dry-run] [--dev] [--no-dev] [--lock] [--no-plugins] [--no-custom-installers] [--no-autoloader] [--no-scripts] [--no-progress] [--with-dependencies] [-v|vv|vvv|--verbose] [-o|--optimize-autoloader] [--ignore-platform-reqs] [--prefer-stable] [--prefer-lowest] [packages1] ... [packagesN]
I used tobie/ua-parser in the past and I am trying to upgrade.
Hi!
Does uap-php support PHP 7.1. I noticed there's no such version in travis config. I also tried to run unit tests and 3 of them failed:
genote:vena gene$ phpunit --verbose vendor/ua-parser/uap-php/
PHPUnit 5.7.5 by Sebastian Bergmann and contributors.
Runtime: PHP 7.1.1
Configuration: /Users/gene/Work/ssp/phpunit.xml
.EEE...................S 24 / 24 (100%)
Time: 1.03 seconds, Memory: 26.00MB
There were 3 errors:
/Users/gene/Work/ssp/vendor/ua-parser/uap-php/tests/ParserTest.php:79
/Users/gene/Work/ssp/vendor/ua-parser/uap-php/tests/ParserTest.php:89
/Users/gene/Work/ssp/vendor/ua-parser/uap-php/tests/ParserTest.php:101
--
There was 1 skipped test:
/Users/gene/Work/ssp/vendor/ua-parser/uap-php/tests/Util/Logfile/AbstractReaderTest.php:55
ERRORS!
Tests: 24, Assertions: 46, Errors: 3, Skipped: 1.
Could it be possible to let the factory read a directory of "LogReader" classes? I'd like to add few more reader classes without touching this code.
How can this be used without Composer? Composer Installation isn't possible on my server
Hi
Why is symfony a required dependency? This should really be a "suggests" than a require, as the docs say you can use this stand alone without the CLI.
Can this be removed please?
Thanks
Hi,
We went from "ua-parser/uap-php": "^3.8, < 3.9" to: "ua-parser/uap-php": "^3.9",
With version 3.8 i had this check in our code
$parser = Parser::create();
$result = $parser->parse($request->headers->get('User-Agent'));
return 1 == $request->request->get('mobile-view') || 'Other' !== $result->device->family;
With this version i could check for 'Other' in order to check if the user is working on a desktop or mobile
When i update to 3.9 the $result->device->family
returns 'MAC' instead of other (in my case i am working on a mac)
That means that for every operating system it will return something else.
Is there something else i can check in order to check if the user is on mobile or on desktop?
I would like to be able to use this package with composer and lock down a version. Currently I am unable to do so. It appears as though the original repo is registered in packagist, it just needs to be updated for this new repo.
Thanks
We recently upgraded our version of PHP from 7.0 to 7.3, and are now receiving many warnings, some of which are pasted below.
You can see the documented changes in the migration notes.
Also note the jump in PCRE versions on the PCRE Installation page.
We also upgraded this library, going from 3.9.1 to 3.9.14 (the latest as of the creation of this issue). Due to the inherent PCRE upgrade in PHP itself, my guess is that is irrelevant, but just thought it should be mentioned anyway.
PHP Warning: preg_match(): Unknown modifier '/' in /var/www/vendor/ua-parser/uap-php/src/AbstractParser.php on line 28
PHP Warning: preg_match(): Unknown modifier '/' in /var/www/vendor/ua-parser/uap-php/src/AbstractParser.php on line 28
PHP Warning: preg_match(): No ending delimiter ';' found in /var/www/vendor/ua-parser/uap-php/src/AbstractParser.php on line 28
PHP Warning: preg_match(): Unknown modifier '/' in /var/www/vendor/ua-parser/uap-php/src/AbstractParser.php on line 28
PHP Warning: preg_match(): Unknown modifier '/' in /var/www/vendor/ua-parser/uap-php/src/AbstractParser.php on line 28
PHP Warning: preg_match(): No ending delimiter ';' found in /var/www/vendor/ua-parser/uap-php/src/AbstractParser.php on line 28
PHP Warning: preg_match(): Unknown modifier '/' in /var/www/vendor/ua-parser/uap-php/src/AbstractParser.php on line 28
PHP Warning: preg_match(): Delimiter must not be alphanumeric or backslash in /var/www/vendor/ua-parser/uap-php/src/AbstractParser.php on line 28
PHP Warning: preg_match(): Delimiter must not be alphanumeric or backslash in /var/www/vendor/ua-parser/uap-php/src/AbstractParser.php on line 28
PHP Warning: preg_match(): Delimiter must not be alphanumeric or backslash in /var/www/vendor/ua-parser/uap-php/src/AbstractParser.php on line 28
PHP Warning: preg_match(): Unknown modifier '?' in /var/www/vendor/ua-parser/uap-php/src/AbstractParser.php on line 28
PHP Warning: preg_match(): Delimiter must not be alphanumeric or backslash in /var/www/vendor/ua-parser/uap-php/src/AbstractParser.php on line 28
PHP Warning: preg_match(): Delimiter must not be alphanumeric or backslash in /var/www/vendor/ua-parser/uap-php/src/AbstractParser.php on line 28
PHP Warning: preg_match(): Unknown modifier 'M' in /var/www/vendor/ua-parser/uap-php/src/AbstractParser.php on line 28
After a recent update I get this error:
Compile Error: Declaration of Parser_9383176::parse($userAgent, array $jsParseBits = Array) must be compatible with UAParser\Parser::parse(string $userAgent, array $jsParseBits = Array): UAParser\Result\Client
Hey there!
My question is that the package versioned by semver or a simple stepping?
I wouldn't open an issue for a question like this :D But the release 3.9.8 introduced a breaking change as a patch version and caused issues with users on PHP 7.1 and below.
This was on purpose and I wrongfully assumed semantic versioning or this slipped through the release process? :D
Anyways, thanks for the answer in advance and keep up the good work!
Dears,
I can't use the composer tool on my website.
Is there another way to install ua-parser ?
Thanks in advance.
Just having a small issue with the 'cache', it is conflicting with my framework cache system. Perhaps a new 'nameing' scheme could be helpful.
We've just found out this issue. At the moment if you use Chrome on mac os x the device recorded by the ua-parser comes out as Other with no branch or model.
This is happening on v3.4.5.
i'm sorry for stupid question
where i can copy source "autoload.php" ?
i can't find it on source..
or someone can create a doc for installing manual without composer?
Hi,
Sorry to open similar issue again but I updated my system to windows 10, and Now on edge browser,
print $result->ua->family;
outputs as Chrome instead of Edge.
This is the output I am getting on your example.
========================================
Edge:
========================================
ua-parser-php Test
ua-parser-php is the PHP library for the ua-parser project. Please use this page to test your browser. ua-parser-php was developed to help support my Detector project.
ua->family: Chrome
ua->major: 42
ua->minor: 0
ua->patch: 2311
ua->toString: Chrome 42.0.2311
ua->toVersionString: 42.0.2311
os->family: Windows
os->major:
os->minor:
os->patch:
os->patch_minor:
os->toString: Windows
os->toVersionString:
device->family: Other
toFullString: Chrome 42.0.2311/Windows
uaOriginal: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.10240
As a temp fix on my website, I am searching for "Edge" using regex in $result->originalUserAgent;
But It would be nice to get Family
as Edge
.
Update :
I re downloaded from composer specifically for 3.4.3 It is still detecting Edge as chrome.
I even checked http://uaparser.dmolsen.com/. Chrome.
Connect as much shit in order to determine the user's browser? Are you serious?! Optimize develop.
Thanks for this repository.
When I use it on my pc, device returned as 'Other' instead of PC. Is it the intended behavior?
The current repository does not exist on packagist.org
. At the tobie/ua-parser
package contains files for other languages which are useless for a PHP application.
I believe ua-parser/ua-parser
package from this repository should be published.
uap-core
now supports Microsoft Edge (it was earlier recognized as IE12, erroneously). Could you update the git submodule so that uap-php
has this change as well?
can i implement this on yii2? 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.