Skip to content

Commit c57f413

Browse files
committed
v2.8
New browsers detection. Fixes and improvements
1 parent 80d7bae commit c57f413

18 files changed

+493
-99
lines changed

CHANGELOG.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,37 @@
22

33
All notable changes to this `PHP Browser Detection` project documented in this file.
44

5+
## [2.8] - 2024-09-03
6+
7+
### Changed
8+
9+
- Safari Mobile browser detection improved;
10+
- Yandex App and Yandex Browser detection improved;
11+
- Baidu Mobile Browser renamed to DU Browser;
12+
- MIUI Browser renamed to Mi Browser;
13+
- Naver Search App renamed to Naver App;
14+
- 115Browser renamed to 115 Browser;
15+
- QQBrowser renamed to QQ Browser;
16+
- AVG Secure Browser renamed to AVG Browser;
17+
- MxNitro renamed to Maxthon Nitro;
18+
- WeChat App moved to cross-device detections.
19+
20+
### Added
21+
22+
- Added detection for: DuckDuckGo, Aloha Browser, Opera GX, Ghostery Browser, SmartTV Browser, Adblock Browser, Stargon, Hi Browser, JioPages, You Browser, Max Browser, Biscuit, Chromium GOST, Dashob, Dezor, Duoyu Browser, Mypal Browser, iTop Browser, Mercury, Polarity, Sielo, Roccat, Arctic Fox, Norton Browser, Avira Browser, Lenovo Browser, Sber Browser, Soul Browser, Samsung Browser TV;
23+
- Gnome Web browser detection on Linux;
24+
- Opera Touch on iOS detection added;
25+
- Chromium OS detection added as Chrome OS.
26+
27+
### Fixed
28+
29+
- MacOS/iOS WKWebView detection fixed and improved;
30+
- Desktop Mode detection fixed and improved for Android and iOS browsers;
31+
- Possible collisions with 'iPad' string matching in User-Agent (e.g HiPad on Android device) fixed;
32+
- Basilisk browser detection fixed;
33+
- Chrome iOS browser detection fixed;
34+
- Firefox iOS browser detection fixed.
35+
536
## [2.7] - 2023-04-27
637

738
### Fixed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2020-2023 Artem Murugov
3+
Copyright (c) 2020-2024 Artem Murugov
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 44 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,19 @@
11
# PHP Browser Detection
22

3-
A PHP library to detect browser, OS, platform and device type by User-Agent parsing.\
4-
This library focused on high performance and low memory usage HTTP client parsing.\
5-
Uses a simple and fast algorithm to accurately detect more than 200 browsers/apps and over 60 OS.\
6-
For most commonly browsers parsing process took less than 0.0005 second even on low-level shared hosting.\
7-
In the case of rare User-Agents recognized time is less than 0.0008 second for the same conditioned hosting environment.\
8-
The library supports only really actual Browsers and OS without support for outdated environments that are actually not used now.\
9-
Newest MacOS Monterey, MacOS Ventura and Windows 11 User-Agents detection included.\
10-
Works by use only one library file and without any third-party libraries dependency.
3+
A PHP library for detecting the browser, operating system (OS), platform, and device type through User-Agent parsing, designed with a focus on high performance and minimal memory usage during HTTP client parsing.\
4+
It uses a simple yet fast algorithm to accurately identify over 200 browsers/apps and more than 60 OS.\
5+
Parsing the most common browsers takes less than 0.0005 seconds, even on low-end shared hosting environments. For rare User-Agents, recognition times are under 0.0008 seconds in the same hosting conditions.\
6+
The library is exclusively tailored for current browsers and OS, omitting support for outdated environments that are no longer in use.\
7+
The library operates using a single file and does not rely on any third-party dependencies.
118

129
## Requirements
1310

14-
This library requires PHP 5.3 or higher.
11+
This library requires PHP 5.3 or later.
1512

1613
## Manual installation
1714

18-
1. Simply upload library file `BrowserDetection.php` (placed in the `src` directory) to your project;
19-
2. Connect PHP library file by using `require_once`:
15+
1. Simply upload the library file `BrowserDetection.php` (located in the `src` directory) to your project;
16+
2. Include the PHP library file using `require_once`:
2017

2118
```php
2219
<?php
@@ -54,8 +51,8 @@ require ('vendor/autoload.php');
5451

5552
## Usage
5653

57-
The library will try to get environment data from the `HTTP_USER_AGENT` header sent by the HTTP client.
58-
Library PHP Class `BrowserDetection` contains four public methods which return Array or JSON string of recognized data from `HTTP_USER_AGENT`:
54+
The library attempts to retrieve environment data from the `HTTP_USER_AGENT` header sent by the HTTP client.\
55+
The `BrowserDetection` PHP class within this library provides four public methods that return either an array or a JSON string containing the detected data extracted from the `HTTP_USER_AGENT`:
5956

6057
* `getAll();`
6158
* `getOS();`
@@ -130,8 +127,8 @@ Example: `Windows`, `Android`, `macOS`, `iOS` etc.
130127
**OS Version** (`os_version`)\
131128
Returns operating system (OS) version or `0` in cases of unable OS version recognition.\
132129
May contains numeric, string or mixed types OS versions.\
133-
In case of numeric OS version (e.g. `Android`) contains major and minor version parts values, e.g. `4.4`, `8.1`, `10` etc.\
134-
In case of string OS version (e.g. `macOS`) contains string version name values, e.g. `Mavericks`, `Mojave`, `Catalina` etc.\
130+
In case of numeric OS version (e.g. `Android`) contains major and minor version parts values, e.g. `4.4`, `8.1`, `10`, `14` etc.\
131+
In case of string OS version (e.g. `macOS`) contains string version name values, e.g. `Mavericks`, `Mojave`, `Catalina`, `Big Sur` etc.\
135132
For `Windows` may contains mixed version types values: `10`, `Vista`, `XP` etc.
136133

137134
**OS Title** (`os_title`)\
@@ -158,7 +155,7 @@ Example: `Chrome`, `Firefox`, `UC Browser`, `Huawei Browser`, `Vivaldi` etc.
158155
Returns browser version number or `0` in cases of unable browser version recognition.\
159156
Always contains numeric values (integer or float numbers).\
160157
Returns float number (e.g. `3.5`, `10.5`, `13.1`) for some browsers which should contains both major and minor browser version parts (`Safari`, `Vivaldi`, `PaleMoon` etc).\
161-
Returns only major decimal browser version (e.g. `15`, `37`, `81`) for other browsers which has a lot of major versions (`Chrome`, `Firefox`, `Opera` etc).
158+
Returns only major decimal browser version (e.g. `15`, `37`, `128`) for other browsers which has a lot of major versions (`Chrome`, `Firefox`, `Opera` etc).
162159

163160
**Browser Title** (`browser_title`)\
164161
Returns browser title which contains browser name and browser version together.\
@@ -199,7 +196,7 @@ Available only for `getAll();` and `getOS();` methods.
199196

200197
## Usage Examples
201198

202-
See follow examples to understand library usage use cases.
199+
Here are some examples to help you understand the library usage scenarios.
203200

204201
### Detect All
205202

@@ -253,7 +250,7 @@ To parse only OS data use:
253250

254251
$Browser = new foroco\BrowserDetection();
255252

256-
$useragent = 'Mozilla/5.0 (Linux; arm_64; Android 9; LLD-L31) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.136 YaBrowser/20.2.4.153.00 Mobile Safari/537.36';
253+
$useragent = 'Mozilla/5.0 (Linux; arm_64; Android 14; SM-G965F) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.6613.99 YaBrowser/24.7.4.147 Mobile Safari/537.36';
257254
$result = $Browser->getOS($useragent);
258255
print_r($result);
259256

@@ -268,8 +265,8 @@ Array
268265
[os_type] => mobile
269266
[os_family] => android
270267
[os_name] => Android
271-
[os_version] => 9
272-
[os_title] => Android 9
268+
[os_version] => 14
269+
[os_title] => Android 14
273270
[64bits_mode] => 1
274271
)
275272
```
@@ -283,7 +280,7 @@ To parse only browser data use:
283280

284281
$Browser = new foroco\BrowserDetection();
285282

286-
$useragent = 'Mozilla/5.0 (iPad; CPU OS 9_3_4 like Mac OS X) AppleWebKit/601.1 (KHTML, like Gecko) CriOS/80.0.3987.122 Mobile/13G35 Safari/601.1.46';
283+
$useragent = 'Mozilla/5.0 (iPhone; CPU iPhone OS 17_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/128.0.6613.98 Mobile/15E148 Safari/604.1';
287284
$result = $Browser->getBrowser($useragent);
288285
print_r($result);
289286

@@ -296,12 +293,12 @@ Returns:
296293
Array
297294
(
298295
[browser_name] => Chrome
299-
[browser_version] => 80
300-
[browser_title] => Chrome 80
296+
[browser_version] => 128
297+
[browser_title] => Chrome 128
301298
[browser_chrome_original] => 1
302299
[browser_firefox_original] => 0
303300
[browser_safari_original] => 0
304-
[browser_chromium_version] => 80
301+
[browser_chromium_version] => 128
305302
[browser_gecko_version] => 0
306303
[browser_webkit_version] => 0
307304
[browser_android_webview] => 0
@@ -344,7 +341,7 @@ To detect if mobile browser works in `Desktop Mode` use:
344341

345342
$Browser = new foroco\BrowserDetection();
346343

347-
$useragent = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36';
344+
$useragent = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36';
348345
$Browser->setTouchSupport(); // Call if Touch events detected in browser by JavaScript code ('ontouchstart' in window)
349346
$result = $Browser->getAll($useragent);
350347
print_r($result);
@@ -364,12 +361,12 @@ Array
364361
[os_title] => Android
365362
[device_type] => mobile
366363
[browser_name] => Chrome
367-
[browser_version] => 81
368-
[browser_title] => Chrome 81
364+
[browser_version] => 128
365+
[browser_title] => Chrome 128
369366
[browser_chrome_original] => 1
370367
[browser_firefox_original] => 0
371368
[browser_safari_original] => 0
372-
[browser_chromium_version] => 81
369+
[browser_chromium_version] => 128
373370
[browser_gecko_version] => 0
374371
[browser_webkit_version] => 0
375372
[browser_android_webview] => 0
@@ -389,7 +386,7 @@ To pasre all possible environment data and returns JSON format string:
389386
$Browser = new foroco\BrowserDetection();
390387

391388
$useragent = 'Mozilla/5.0 (iPhone; CPU iPhone OS 6_0 like Mac OS X) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Mobile Safari/537.36';
392-
$result = $Browser->getAll($useragent);
389+
$result = $Browser->getAll($useragent, 'JSON');
393390
print_r($result);
394391

395392
?>
@@ -403,7 +400,7 @@ Returns:
403400

404401
## Benchmarking Test
405402

406-
Benchmarking was performed on a low-level shared hosting.\
403+
Benchmarking was performed on a low-level shared hosting environment.\
407404
Test server configuration: RedHat Linux + LiteSpeed + PHP Extension.\
408405
Test conditions based on collection of random ~446000 non repeated real life User-Agent strings.
409406

@@ -416,11 +413,27 @@ getBrowser: ~ 43000 rps
416413
getDevice: ~ 70000 rps
417414
```
418415

416+
## Important notice
417+
418+
Unfortunately, the major browser engines have "frozen" the OS version information in the User-Agent header.\
419+
For example, on macOS, the OS version information in the User-Agent is **"frozen"** at the `macOS Big Sur` release level (`Mac OS X 10_15_7`).\
420+
On Windows, the OS version information is **"frozen"** in the User-Agent at the `Windows 10` release level (`Windows NT 10.0`).
421+
422+
Recent releases of WebKit, Chromium, and Gecko-based browsers no longer include **correct** current OS version information in the User-Agent header.
423+
424+
**See reference**:
425+
426+
https://issues.chromium.org/issues/40167872
427+
https://bugzilla.mozilla.org/show_bug.cgi?id=1679929
428+
https://bugs.webkit.org/show_bug.cgi?id=217364
429+
430+
One approach is to use the HTTP Client Hints headers, specifically the Sec-CH-UA-Platform-Version header. It's important to note, however, that only Chromium-based browsers currently support sending Client Hints headers.
431+
419432
## License
420433

421434
The MIT License (MIT)
422435

423-
Copyright (c) 2020-2023 Artem Murugov
436+
Copyright (c) 2020-2024 Artem Murugov
424437

425438
Permission is hereby granted, free of charge, to any person obtaining a copy of
426439
this software and associated documentation files (the "Software"), to deal in

0 commit comments

Comments
 (0)