Giter Site home page Giter Site logo

donatj / phpuseragent Goto Github PK

View Code? Open in Web Editor NEW
555.0 36.0 129.0 442 KB

Lightning Fast, Minimalist PHP User Agent String Parser.

Home Page: https://donatstudios.com/PHP-Parser-HTTP_USER_AGENT

License: MIT License

PHP 97.93% Makefile 2.07%
user-agent-parser browser ua-parser php composer

phpuseragent's Introduction

PHP User Agent Parser

Join the chat at https://gitter.im/PhpUserAgentParser/Lobby

Latest Stable Version Total Downloads License ci.yml

What It Is

A simple, streamlined PHP user-agent parser!

Licensed under the MIT license: https://www.opensource.org/licenses/mit-license.php

Upgrading to 1.*

The new 1.* release does not break compatibility with 0.* and nothing need to change to upgrade. However, the global parse_user_agent is now deprecated; it has been replaced with the namespaced \donatj\UserAgent\parse_user_agent and functions exactly the same. You can easily replace any existing call to parse_user_agent with \donatj\UserAgent\parse_user_agent

In addition, 1.x adds a convenience object wrapper you may use should you prefer. More information on this is in the Usage section below.

Why Use This

You have your choice in user-agent parsers. This one detects all modern browsers in a very light, quick, understandable fashion. It is less than 200 lines of code, and consists of just three regular expressions! It can also correctly identify exotic versions of IE others fail on.

It offers 100% unit test coverage, is installable via Composer, and is very easy to use.

What It Does Not Do

This is not meant as a browser "knowledge engine" but rather a simple parser. Anything not adequately provided directly by the user agent string itself will simply not be provided by this.

OS Versions

User-agent strings are not a reliable source of OS Version!

  • Many agents simply don't send the information.
  • Others provide varying levels of accuracy.
  • Parsing Windows versions alone almost nearly doubles the size of the code.

I'm much more interested in keeping this thing tiny and accurate than adding niché features and would rather focus on things that can be done well.

All that said, there is the start of a branch to do it I created for a client if you want to poke it, I update it from time to time, but frankly if you need to reliably detect OS Version, using user-agent isn't the way to do it. I'd go with JavaScript.

Undetectable Browsers

  • Brave - Brave is simply not differentiable from Chrome. This was a design decision on their part.

Undetectable Platforms

  • iPadOS 13+ - Starting with iPadOS 13 and further hardened in 14, iPadOS returns the exact same string as macOS. It is no longer distinguishable by UA string. (See: #69)

Requirements

  • php: >=5.4.0
  • ext-ctype: *

Installing

PHP User Agent is available through Packagist via Composer.

Install the latest version with:

composer require 'donatj/phpuseragentparser'

Usage

The classic procedural use is as simple as:

<?php

// if you're using composer
require __DIR__ . '/../vendor/autoload.php';

// v0 style global function - @deprecated
$uaInfo = parse_user_agent();
// or
// modern namespaced function
$uaInfo = donatj\UserAgent\parse_user_agent();

echo $uaInfo[donatj\UserAgent\PLATFORM] . PHP_EOL;
echo $uaInfo[donatj\UserAgent\BROWSER] . PHP_EOL;
echo $uaInfo[donatj\UserAgent\BROWSER_VERSION] . PHP_EOL;

The new object-oriented wrapper form:

<?php

use donatj\UserAgent\UserAgentParser;

// if you're using composer
require __DIR__ . '/../vendor/autoload.php';

$parser = new UserAgentParser();

// object-oriented call
$ua = $parser->parse();
// or
// command style invocation
$ua = $parser();

echo $ua->platform() . PHP_EOL;
echo $ua->browser() . PHP_EOL;
echo $ua->browserVersion() . PHP_EOL;

Currently Detected Platforms

Predefined helper constants from donatj\UserAgent\Platforms

Constant Platform
Platforms::MACINTOSH Macintosh
Platforms::CHROME_OS Chrome OS
Platforms::LINUX Linux
Platforms::WINDOWS Windows
Platforms::ANDROID Android
Platforms::BLACKBERRY BlackBerry
Platforms::FREEBSD FreeBSD
Platforms::IPAD iPad
Platforms::IPHONE iPhone
Platforms::IPOD iPod
Platforms::KINDLE Kindle
Platforms::KINDLE_FIRE Kindle Fire
Platforms::NETBSD NetBSD
Platforms::NEW_NINTENDO_3DS New Nintendo 3DS
Platforms::NINTENDO_3DS Nintendo 3DS
Platforms::NINTENDO_DS Nintendo DS
Platforms::NINTENDO_SWITCH Nintendo Switch
Platforms::NINTENDO_WII Nintendo Wii
Platforms::NINTENDO_WIIU Nintendo WiiU
Platforms::OPENBSD OpenBSD
Platforms::PLAYBOOK PlayBook
Platforms::PLAYSTATION_3 PlayStation 3
Platforms::PLAYSTATION_4 PlayStation 4
Platforms::PLAYSTATION_5 PlayStation 5
Platforms::PLAYSTATION_VITA PlayStation Vita
Platforms::SAILFISH Sailfish
Platforms::SYMBIAN Symbian
Platforms::TIZEN Tizen
Platforms::WINDOWS_PHONE Windows Phone
Platforms::XBOX Xbox
Platforms::XBOX_ONE Xbox One

Currently Detected Browsers

Predefined helper constants from donatj\UserAgent\Browsers

Constant Browser
Browsers::ADSBOT_GOOGLE AdsBot-Google
Browsers::ANDROID_BROWSER Android Browser
Browsers::APPLEBOT Applebot
Browsers::BAIDUSPIDER Baiduspider
Browsers::BINGBOT bingbot
Browsers::BLACKBERRY_BROWSER BlackBerry Browser
Browsers::BROWSER Browser
Browsers::BUNJALLOO Bunjalloo
Browsers::CAMINO Camino
Browsers::CHROME Chrome
Browsers::CURL curl
Browsers::EDGE Edge
Browsers::FACEBOOKEXTERNALHIT facebookexternalhit
Browsers::FEEDVALIDATOR FeedValidator
Browsers::FIREFOX Firefox
Browsers::GOOGLEBOT Googlebot
Browsers::GOOGLEBOT_IMAGE Googlebot-Image
Browsers::GOOGLEBOT_VIDEO Googlebot-Video
Browsers::HEADLESSCHROME HeadlessChrome
Browsers::IEMOBILE IEMobile
Browsers::IMESSAGEBOT iMessageBot
Browsers::KINDLE Kindle
Browsers::LYNX Lynx
Browsers::MIDORI Midori
Browsers::MIUIBROWSER MiuiBrowser
Browsers::MSIE MSIE
Browsers::MSNBOT_MEDIA msnbot-media
Browsers::NETFRONT NetFront
Browsers::NINTENDOBROWSER NintendoBrowser
Browsers::OCULUSBROWSER OculusBrowser
Browsers::OPERA Opera
Browsers::PUFFIN Puffin
Browsers::SAFARI Safari
Browsers::SAILFISHBROWSER SailfishBrowser
Browsers::SAMSUNGBROWSER SamsungBrowser
Browsers::SILK Silk
Browsers::TELEGRAMBOT TelegramBot
Browsers::TIZENBROWSER TizenBrowser
Browsers::TWITTERBOT Twitterbot
Browsers::UC_BROWSER UC Browser
Browsers::VALVE_STEAM_TENFOOT Valve Steam Tenfoot
Browsers::VIVALDI Vivaldi
Browsers::WGET Wget
Browsers::WORDPRESS WordPress
Browsers::YANDEX Yandex
Browsers::YANDEXBOT YandexBot

More information is available at Donat Studios.

phpuseragent's People

Contributors

atomantic avatar bitdeli-chef avatar dacorp avatar dependabot[bot] avatar donatj avatar frankmayer avatar gitter-badger avatar goshoo avatar henrybaxter avatar kocsismate avatar landy2005 avatar manavo avatar rotzbua avatar simsimy avatar stromajer avatar toolstack avatar

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

phpuseragent's Issues

UC Browser not detected

My Android UC Browser uses this UA string:
Mozilla/5.0 (Linux; U; Android 6.0; en-US; ZTE BLADE V7 Build/MRA58K) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/57.0.2987.108 UCBrowser/13.0.8.1291 Mobile Safari/537.36

when passing this to parse_user_agent, the result is:
Android/Chrome/57.0.2987.108

Edge?

How about the new Edge browser? :-)

Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.10240

Support reading system details even the user agent is not fully written

Thank you for this amazing function <3

Current version does not support reading details in User-Agent if it is not full detailed.
Example:
User-Agent: AppName/1.0.23 (example.com/AppName; [email protected]).

It just read the AppName with version and does not read the system details.

This case usually used when contacting APIs where everyone should write self-described User-Agent.

Many Thanks

Consistent detection of "Safari shells" in iOS

After giving up on some "simple regex" to detect common browsers (yep, you know for which project lol), I landed in this library :)
Thus, I already had a bunch of UA strings to test against; I noticed that, while iPhone/CriOS is detected as Chrome on iPhone, FxiOS and EdgiOS end up simply as Safari.

This seems related to #40 since there might not be much value on distinguishing them all, but looking from a statistical POV, it would make some sense to separate the shells from the actual Safari. Besides that, consistency is always good :)

Samples:

Mozilla/5.0 (iPhone; CPU iPhone OS 15_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/103.0.5060.63 Mobile/15E148 Safari/604.1
Mozilla/5.0 (iPad; CPU OS 15_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/103.0.5060.63 Mobile/15E148 Safari/604.1
Mozilla/5.0 (iPhone; CPU iPhone OS 12_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) FxiOS/101.0 Mobile/15E148 Safari/605.1.15
Mozilla/5.0 (iPad; CPU OS 12_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) FxiOS/101.0 Mobile/15E148 Safari/605.1.15
Mozilla/5.0 (iPhone; CPU iPhone OS 15_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.0 EdgiOS/100.1185.50 Mobile/15E148 Safari/605.1.15

Windows Phone wrong detection

Hi,
This UA is from a Nokia Lumia Windows Phone:
"Mozilla/5.0 (Mobile; Windows Phone 8.1; Android 4.0; ARM; Trident/7.0; Touch; rv:11.0; IEMobile/11.0; NOKIA; Lumia 920; Vodafone ES) like iPhone OS 7_0_3 Mac OS X AppleWebkit/537 (KHTML, like Gecko) Mobile Safari/537"
But it is detected as:
System: Android
Name: IEMobile
Version: 11.0

I think that the problem is in the call to "array_intersect($priority, $result['platform'])" who give priority to Android over Windows Phone.

Any solution to this??

Can Not Detect iPadOS 13+

So the people at Apple are bad bad people and made it much more difficult to detect iPad OS

https://developer.apple.com/forums/thread/119186

iPad OS Safari

Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0 Safari/605.1.15

MacOS Safari

Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36

There are three major sniffable differences as best I can tell - ordered by seemingly most to least important.

  • The Mac OS X version includes 3 places in macOS but only two places in iOS
  • iPad OS does not claim to be chrome
  • The version of AppleWebKit in macOS only has two places rather than 3

While I don't normally support meddling with this kind of UA shenanigans, iPadOS seems important enough to bother.

Running Firefox on iPad shows Safari

User Agent is:
Mozilla/5.0 (iPad; CPU OS 10_2_1 like Mac OS X) AppleWebKit/602.4.6 (KHTML, like Gecko) FxiOS/6.1 Mobile/14D27 Safari/602.4.6

Reports iPad, Safari, 602.4.6
Should report iPad, Firefox, 6.1

The FxiOS keyword should take priority over AppleWebKit and Safari

Windows OS version

It would be nice if you could output the OS version number as well as the browser version number. I am finding that the same browser running on XP behaves differently than on Windows 8 and it would be nice to know the difference when using your project's output.

Suggestion: detect bots

This PHP function is simply awesome! It only misses bot detection...it would be so nice to add platform type "bot" and browser types "googlebot", "bingbot", "yahoo slurp", etc... ;-)

No recognition of e-mail clients

Very nice feature.

Unfortunately, he does not recognize e-mail clients.
I used this to track mailing openings by downloading a remote image and does not recognize anything.

Example User-Agent for Thunderbird

Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 Lightning/5.4.9.1

For Gmail (by GoogleImagesProxy)

Mozilla/5.0 (Windows NT 5.1; rv:11.0) Gecko Firefox/11.0 (via ggpht.com GoogleImageProxy)

Thanks, Andrzej

Add version number to header?

I see this included in places and wonder which version it actually is. Just dropping the version up top would be a major help, rather than me staring at it/diffing/etc...

/**
 * Parses a user agent string into its important parts
 *
 * @version 306.2.97 or whatever...
 * @author Jesse G. Donat <[email protected]>
 * @link https://github.com/donatj/PhpUserAgent
 * @link http://donatstudios.com/PHP-Parser-HTTP_USER_AGENT
 * @param string|null $u_agent User agent string to parse or null. Uses $_SERVER['HTTP_USER_AGENT'] on NULL
 * @throws \InvalidArgumentException on not having a proper user agent to parse.
 * @return string[] an array with browser, version and platform keys
 */

Support Chrome based MS Edge

Preliminary Issue Information:

Current Canary UA as of May 20th, 2019

Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3794.0 Safari/537.36 Edg/76.0.161.0

Web bots

I do have some visitors on my sites that are web bots. You can guess that. I have made a quite extensive list of platforms, you can pick in it as you please. Your list of headed browser is larger than mine, but the list I have made for headless browser is a little but more extended.

private $platforms = array(
"mobile"   => array("ipod","iphone","ipad","android","blackberry","symbos","symbian","s60","Opera Mini","windows ce","palm","webos","wii"),
"desktop"  => array("windows","win32","macintosh","mac os x","linux","openbsd","sunos","beos"),
);
private $browsers = array(
"headed" => array("msie","trident"
"opera","opera mobile"
"safari","mobile safari"
"chrome");//headless
"headless" => array("curl","wget","httpclient","ice","links","lynx","java","netcraft"),
"web bots" => array("baidu","googlebot","msnbot","bingbot","yandexbot","taota","zmeu","aboutusbot","revolt","sogou", "spider", "surveybot")
);

I use this as a hint of the kind of page I need to send but PhpUserAgent is addressing only part of this. All the platforms you can integrate in there are good for me. I can't do it myself, your code is quite undocummented :(

Thanks.

Opera Next

Running the latest version of Opera on macOS has this user agent string:

Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36 OPR/63.0.3368.94

Which is incorrectly being reported as "Opera Next" (Opera's beta version) rather than just "Opera".

object mode

use donatj\UserAgent\UserAgentParser;

not working,
is namespace definition right?

Download

Cannot download zip file - getting 500 Server Error.
I do want to thank you for writing this!

Detect Vivaldi

Hi, what about the new Vivaldi browser?

The string is: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.89 Vivaldi/1.0.83.38 Safari/537.36 and is identified as Chrome 40.

What about rendering engine?

What do you think about grabbing the rendering engine (Gecko/WebKit/Blink/etc) and putting that in the output array as well, maybe with a key of engine?

Rename Macintosh to Mac

Hello

Could we perhaps rename the Macintosh platform to simply Mac? It hasn't been branded as Macintosh since 1998, and I'd like to avoid having to "translate" this to Mac for newer users that simply don't know what a Macintosh is.

Can you add more Chinese browsers

Can you add more Chinese browsers。

115Browser

Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36 115Browser/26.0.2.5

360Browser

Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.6045.160 Safari/537.36 QIHU 360EE

Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.6261.95 Safari/537.36 QIHU 360SE

Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.121 Safari/537.36

Baidu

Mozilla/5.0 (Linux; Android 12; 22041211AC Build/SP1A.210812.016; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/97.0.4692.98 Mobile Safari/537.36 T7/13.54 SP-engine/2.92.0 baiduboxapp/13.54.0.10 (Baidu; P1 12) NABar/1.0

QuarkBrowser

Mozilla/5.0 (Linux; U; Android 9; zh-CN; MI 6 Build/PKQ1.190118.001) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.108 Quark/5.5.5.204 Mobile Safari/537.36

Mozilla/5.0 (Windows; U; Windows NT 5.2;. en-US) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.58 Safari/537.36 Quark/6.10.5.520

QQBrowser / QQ

Mozilla/5.0 (Linux; U; Android 10; zh-cn; MI 6 Build/SP1A.210812.016) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/96.0.4664.104 MQQBrowser/14.9 Mobile Safari/537.36

Mozilla/5.0 (Linux; Android 10; MI 6 Build/SP1A.210812.016; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/109.0.5414.86 MQQBrowser/6.2 TBS/047001 Mobile Safari/537.36 V1_AND_SQ_8.9.76_4484_YYB_D PA QQ/8.9.76.12115 NetType/WIFI WebP/0.3.0 AppId/537173574 Pixel/1080 StatusBarHeight/79 SimpleUISwitch/1 QQTheme/3491 StudyMode/0 CurrentMode/1 CurrentFontScale/1.0 GlobalDensityScale/1.0 AllowLandscape/false InMagicWin/0

WeChat

Mozilla/5.0 (Linux; Android 10; MI 6 Build/SP1A.210812.016; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/107.0.5304.141 Mobile Safari/537.36 XWEB/5315 MMWEBSDK/20220706 MMWEBID/7498 MicroMessenger/8.0.25.2200(0x28001935) WeChat/arm64 Weixin NetType/WIFI Language/zh_CN ABI/arm64

More browsers are no longer listed.

Platform version support

Can you please add platform version support?
For example WinXP, Win7, Win8, etc.
Thank you in anticipation.

Incorrect browser detected for "Motorola Edge"

Hi,

In the company I work, we've been using this library for a long time and we had no issues until now. Recently we faced user-agent Mozilla/5.0 (Linux; Android 11; motorola edge 20 lite) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.5005.78 Mobile Safari/537.36.

Result from the library:

[
    'platform' => 'Android',
    'browser' => 'Edge',
    'browserVersion' => '20',
]

Expected result:

[
    'platform' => 'Android',
    'browser' => 'Chrome',
    'browserVersion' => '102.0.5005.78',
]

Right now we are using dirty fix to prevent that.
Thanks in advance for your hard work to check this one!

Move the function to a class

Hi,

is it possible that you move your function inside a class / method?

With the function only approach, i have a lot of problems in case of testing / mocking.

Instagram and Snapchat browsers

Can you detect them?

Mozilla/5.0 (iPhone; CPU iPhone OS 13_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 Instagram 159.0.0.28.123 (iPhone11,8; iOS 13_7; cs_CZ; cs-CZ; scale=2.00; 828x1792; 244425769)

Mozilla/5.0 (iPhone; CPU iPhone OS 13_6_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Snapchat/11.1.0.65 (iPhone12,1; iOS 13.6.1; gzip)

Thanks

PlayStation 3 Support

Currently the PS3 is not seen properly, depending on what version of software the PlayStation is running it will either have all fields blank or have a version entry only. The two examples of the user agent I have are:

Mozilla/5.0 (PLAYSTATION 3; 1.00)
Mozilla/5.0 (PLAYSTATION 3 4.20) AppleWebKit/531.22.8 (KHTML, like Gecko)

I have added crude support. Here is my patch.

*** Source/UserAgentParser.php  Tue Aug 28 14:00:19 2012
--- Source/UserAgentParser.php  Tue Aug 28 14:01:12 2012
***************
*** 19,26 ****

    if( preg_match('/\((.*?)\)/im', $u_agent, $regs) ) {

!       # (?<platform>Android|iPhone|iPad|Windows|Linux|Macintosh|Windows Phone OS|Silk|linux-gnu|BlackBerry)(?: i386| i686| x86_64)?(?: NT)?(?:[ /][0-9._]+)*(;|$)
!       preg_match_all('%(?P<platform>Android|iPhone|iPad|Windows|Linux|Macintosh|Windows Phone OS|Silk|linux-gnu|BlackBerry)(?: i386| i686| x86_64)?(?: NT)?(?:[ /][0-9._]+)*(;|$)%iim', $regs[1], $result, PREG_PATTERN_ORDER);
        $result['platform'] = array_unique($result['platform']);
        if( count($result['platform']) > 1 ) {
            if( ($key = array_search( 'Android', $result['platform'] )) !== false ) {
--- 19,26 ----

    if( preg_match('/\((.*?)\)/im', $u_agent, $regs) ) {

!       # (?<platform>Android|iPhone|iPad|Windows|Linux|Macintosh|Windows Phone OS|Silk|linux-gnu|BlackBerry|PLAYSTATION 3)(?: i386| i686| x86_64)?(?: NT)?(?:[ /][0-9._]+)*(;|$)
!       preg_match_all('%(?P<platform>Android|iPhone|iPad|Windows|Linux|Macintosh|Windows Phone OS|Silk|linux-gnu|BlackBerry|PLAYSTATION 3)(?: i386| i686| x86_64)?(?: NT)?(?:[ /][0-9._]+)*(;|$)%iim', $regs[1], $result, PREG_PATTERN_ORDER);
        $result['platform'] = array_unique($result['platform']);
        if( count($result['platform']) > 1 ) {
            if( ($key = array_search( 'Android', $result['platform'] )) !== false ) {
***************
*** 77,82 ****
--- 77,88 ----
        $data['browser'] = $result['browser'][0];
        $data['version'] = $result['version'][0];
    }
+   if($data['platform'] == 'PLAYSTATION 3'){
+       $data['platform'] = 'PlayStation';
+       $data['browser'] = 'PS3 Browser';
+       preg_match_all('%(?P<version>[0-9.]{4})%im', $u_agent, $result, PREG_PATTERN_ORDER);
+       $data['version'] = $result['version'][0];
+   }

    return $data;

Ruby port

Hello all

I made a Ruby port of PhpUserAgent.
See PHP version and Ruby version (you can compare line by line).

Do as you want of this first version.

Add user_agent initial string to output

Please add user_agent key (with initial u_agent variable value) to return. It's usefull to operate with the whole object - initial string, platform, browser, version - to insert into DB rather than with 2 different variables, initial ua and user_agent array.

Add Platform Version

It'd be great to gather the platform version where possible.
Such as "Windows 10", and for extra brownie points browser version too.

I'd love to see this added.

Thanks!

Googlebot Mobile not Detected

Hi,

For this user agent :
Mozilla/5.0 (Linux; Android 6.0.1; Nexus 5X Build/MMB29P) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.97 Mobile Safari/537.36 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)

parse_user_agent() return :
browser => Chrome
platform => Android
version => 90.0.4430.97

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.