You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+44-31Lines changed: 44 additions & 31 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,22 +1,19 @@
1
1
# PHP Browser Detection
2
2
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.
11
8
12
9
## Requirements
13
10
14
-
This library requires PHP 5.3 or higher.
11
+
This library requires PHP 5.3 or later.
15
12
16
13
## Manual installation
17
14
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`:
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`:
59
56
60
57
*`getAll();`
61
58
*`getOS();`
@@ -130,8 +127,8 @@ Example: `Windows`, `Android`, `macOS`, `iOS` etc.
130
127
**OS Version** (`os_version`)\
131
128
Returns operating system (OS) version or `0` in cases of unable OS version recognition.\
132
129
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.\
135
132
For `Windows` may contains mixed version types values: `10`, `Vista`, `XP` etc.
Returns browser version number or `0` in cases of unable browser version recognition.\
159
156
Always contains numeric values (integer or float numbers).\
160
157
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).
162
159
163
160
**Browser Title** (`browser_title`)\
164
161
Returns browser title which contains browser name and browser version together.\
@@ -199,7 +196,7 @@ Available only for `getAll();` and `getOS();` methods.
199
196
200
197
## Usage Examples
201
198
202
-
See follow examples to understand library usage use cases.
199
+
Here are some examples to help you understand the library usage scenarios.
203
200
204
201
### Detect All
205
202
@@ -253,7 +250,7 @@ To parse only OS data use:
253
250
254
251
$Browser = new foroco\BrowserDetection();
255
252
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';
257
254
$result = $Browser->getOS($useragent);
258
255
print_r($result);
259
256
@@ -268,8 +265,8 @@ Array
268
265
[os_type] => mobile
269
266
[os_family] => android
270
267
[os_name] => Android
271
-
[os_version] => 9
272
-
[os_title] => Android 9
268
+
[os_version] => 14
269
+
[os_title] => Android 14
273
270
[64bits_mode] => 1
274
271
)
275
272
```
@@ -283,7 +280,7 @@ To parse only browser data use:
283
280
284
281
$Browser = new foroco\BrowserDetection();
285
282
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';
287
284
$result = $Browser->getBrowser($useragent);
288
285
print_r($result);
289
286
@@ -296,12 +293,12 @@ Returns:
296
293
Array
297
294
(
298
295
[browser_name] => Chrome
299
-
[browser_version] => 80
300
-
[browser_title] => Chrome 80
296
+
[browser_version] => 128
297
+
[browser_title] => Chrome 128
301
298
[browser_chrome_original] => 1
302
299
[browser_firefox_original] => 0
303
300
[browser_safari_original] => 0
304
-
[browser_chromium_version] => 80
301
+
[browser_chromium_version] => 128
305
302
[browser_gecko_version] => 0
306
303
[browser_webkit_version] => 0
307
304
[browser_android_webview] => 0
@@ -344,7 +341,7 @@ To detect if mobile browser works in `Desktop Mode` use:
344
341
345
342
$Browser = new foroco\BrowserDetection();
346
343
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';
348
345
$Browser->setTouchSupport(); // Call if Touch events detected in browser by JavaScript code ('ontouchstart' in window)
349
346
$result = $Browser->getAll($useragent);
350
347
print_r($result);
@@ -364,12 +361,12 @@ Array
364
361
[os_title] => Android
365
362
[device_type] => mobile
366
363
[browser_name] => Chrome
367
-
[browser_version] => 81
368
-
[browser_title] => Chrome 81
364
+
[browser_version] => 128
365
+
[browser_title] => Chrome 128
369
366
[browser_chrome_original] => 1
370
367
[browser_firefox_original] => 0
371
368
[browser_safari_original] => 0
372
-
[browser_chromium_version] => 81
369
+
[browser_chromium_version] => 128
373
370
[browser_gecko_version] => 0
374
371
[browser_webkit_version] => 0
375
372
[browser_android_webview] => 0
@@ -389,7 +386,7 @@ To pasre all possible environment data and returns JSON format string:
389
386
$Browser = new foroco\BrowserDetection();
390
387
391
388
$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');
393
390
print_r($result);
394
391
395
392
?>
@@ -403,7 +400,7 @@ Returns:
403
400
404
401
## Benchmarking Test
405
402
406
-
Benchmarking was performed on a low-level shared hosting.\
403
+
Benchmarking was performed on a low-level shared hosting environment.\
407
404
Test server configuration: RedHat Linux + LiteSpeed + PHP Extension.\
408
405
Test conditions based on collection of random ~446000 non repeated real life User-Agent strings.
409
406
@@ -416,11 +413,27 @@ getBrowser: ~ 43000 rps
416
413
getDevice: ~ 70000 rps
417
414
```
418
415
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.
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
+
419
432
## License
420
433
421
434
The MIT License (MIT)
422
435
423
-
Copyright (c) 2020-2023 Artem Murugov
436
+
Copyright (c) 2020-2024 Artem Murugov
424
437
425
438
Permission is hereby granted, free of charge, to any person obtaining a copy of
426
439
this software and associated documentation files (the "Software"), to deal in
0 commit comments