Skip to content

Commit 0029f17

Browse files
committed
Version 2.0 (release)
1 parent d0011c2 commit 0029f17

File tree

10 files changed

+919
-254
lines changed

10 files changed

+919
-254
lines changed

CHANGELOG.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Changelog
2+
3+
All notable changes to this `PHP Browser Detection` project documented in this file.
4+
5+
## [2.0] - 2021-03-12
6+
7+
### Added
8+
9+
- More than 40 browsers detection added;
10+
- 64bits mode detection;
11+
- MacOS Big Sur detection;
12+
- Darwin OS detection and it's versions to MacOS/iOS versions corresponding detection;
13+
- MacOS/iOS Apps detection;
14+
- Roku OS detection;
15+
- MAUI Platform detection;
16+
- PlayStation Platform detection.
17+
18+
### Changed
19+
20+
- User-Agent matching performance improvements;
21+
- Matching methods optimization;
22+
- Mobile operation systems and devices matching improvements;
23+
- Desktop mode matching accuracy improvements for Android browsers;
24+
- Desktop mode matching accuracy improvements for Windows Phone;
25+
- Android WebView detection improvements;
26+
- Safari WebView (iOS) detection improvements;
27+
- Console and TV devices detection improvements;
28+
- Linux OS detection improvements;
29+
- Safari and Safari Mobile browsers matching accuracy improvements;
30+
- Opera browser matching optimization and improvements;
31+
- Fixed some minor inaccuracy browser matching.
32+
33+
## [1.1] - 2020-06-10
34+
35+
### Added
36+
37+
- Desktop mode detection for mobile browsers (Android, iOS, Windows Phone);
38+
- More than 20 browsers detection added.
39+
40+
### Changed
41+
42+
- Windows OS detection improvements;
43+
- Linux OS detection improvements;
44+
- Fixed some minor inaccuracy User-Agent matching.
45+
46+
## [1.0] - 2020-05-22
47+
48+
### First release.

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 Artem Murugov
3+
Copyright (c) 2020-2021 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: 24 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
A PHP library to detect browser, OS, platform and device type by User-Agent parsing.\
44
This library focused on high performance and low memory usage HTTP client parsing.\
5-
Uses a simple and fast algorithm to accurate detection more than 120 browsers types and ~ 58 OS types.\
6-
For most commonly browsers parsing process tooks less than 0.0005 second even on low-level shared hosting.\
7-
In the case of very unusual User-Agents recognized time is less than 0.0008 second for same conditioned hosting environment.\
5+
Uses a simple and fast algorithm to accurately detect more than 165 browser types and over 60 OS types.\
6+
For most commonly browsers parsing process took less than 0.0005 second even on low-level shared hosting.\
7+
In the case of very unusual User-Agents recognized time is less than 0.0008 second for the same conditioned hosting environment.\
88
The library supports only really actual Browsers and OS without support for outdated environments that are actually not used now.\
99
Works by use only one library file and without any third-party libraries dependency.
1010

@@ -20,20 +20,20 @@ To install, you can use composer:
2020
composer require foroco/php-browser-detection
2121
`
2222

23-
Or simply upload library file `BrowserDetection.php` (placed in the `src` directory) to your project and connect it in PHP script by use `require_once` (see usage cases bellow).
23+
Or simply upload library file `BrowserDetection.php` (placed in the `src` directory) to your project and connect it in PHP script by using `require_once` (see usage cases bellow).
2424

2525
## Usage
2626

2727
The library will try to get environment data from the `HTTP_USER_AGENT` header sent by the HTTP client.
28-
Library PHP Class `BrowserDetection` contains four public methods which returns Array or JSON string of recognized data from `HTTP_USER_AGENT`:
28+
Library PHP Class `BrowserDetection` contains four public methods which return Array or JSON string of recognized data from `HTTP_USER_AGENT`:
2929

3030
* `getAll();`
3131
* `getOS();`
3232
* `getBrowser();`
3333
* `getDevice();`
3434

35-
First argument should contains User-Agent string from the `HTTP_USER_AGENT` header or your custom User-Agent string.\
36-
Second argument (optional) may contains 'JSON' if you want to get returned result as JSON format.
35+
First argument should contain User-Agent string from the `HTTP_USER_AGENT` header or your custom User-Agent string.\
36+
Second argument (optional) may contain 'JSON' if you want to get returned result as JSON format.
3737

3838
```php
3939
<?php
@@ -69,7 +69,7 @@ $result = $Browser->getAll($useragent, 'JSON');
6969
The library class `BrowserDetection` also contains special method `setTouchSupport()` (optional, available from version 1.1).\
7070
This method is necessary to detect mobile browsers in `Desktop Mode` condition (Android and iOS).\
7171
For `Desktop Mode` detection `setTouchSupport()` method should call if browser supports Touch events.\
72-
Touch events detection performed by client-side JavaScript code in the target browser. Example:
72+
Touch events detection is performed by client-side JavaScript code in the target browser. Example:
7373

7474
```javascript
7575
if (('ontouchstart' in window) || window.DocumentTouch && document instanceof DocumentTouch) {
@@ -161,6 +161,10 @@ Returns `1` number if iOS Webview mode detected or returns `0` if it's not.
161161
Returns `1` number if mobile browser works in `Desktop Mode` or returns `0` if it's not detected.\
162162
`setTouchSupport()` method should call for `Desktop Mode` detection if browser supports Touch events.
163163

164+
**64 Bits Mode** (`64bits_mode`)\
165+
Returns `1` number if operating system (OS) and browser work together in 64-bit mode or returns `0` if 64-bit mode not detected.\
166+
Available only for `getAll();` and `getOS();` methods.\
167+
164168
## Usage Examples
165169

166170
See follow examples to understand library usage use cases.
@@ -203,6 +207,7 @@ Array
203207
[browser_android_webview] => 0
204208
[browser_ios_webview] => 0
205209
[browser_desktop_mode] => 0
210+
[64bits_mode] => 1
206211
)
207212
```
208213

@@ -215,7 +220,7 @@ To parse only OS data use:
215220
require_once('BrowserDetection.php');
216221
$Browser = new foroco\BrowserDetection();
217222

218-
$useragent = 'Mozilla/5.0 (Android 8.1.0; Tablet; rv:68.6.0) Gecko/68.6.0 Firefox/68.6.0';
223+
$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';
219224
$result = $Browser->getBrowser($useragent);
220225
print_r($result);
221226
?>
@@ -229,8 +234,9 @@ Array
229234
[os_type] => mobile
230235
[os_family] => android
231236
[os_name] => Android
232-
[os_version] => 8.1
233-
[os_title] => Android 8.1
237+
[os_version] => 9
238+
[os_title] => Android 9
239+
[64bits_mode] => 1
234240
)
235241
```
236242

@@ -278,8 +284,8 @@ To parse only device type data use:
278284
require_once('BrowserDetection.php');
279285
$Browser = new foroco\BrowserDetection();
280286

281-
$useragent = 'MEmpresas/20180706 CFNetwork/808.2.16 Darwin/17.4.0';
282-
$result = $Browser->getBrowser($useragent);
287+
$useragent = 'Mozilla/5.0 (SMART-TV; Linux; Tizen 5.0) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/2.2 Chrome/63.0.3239.84 TV Safari/537.36';
288+
$result = $Browser->getDevice($useragent);
283289
print_r($result);
284290
?>
285291
```
@@ -289,13 +295,13 @@ Returns:
289295
```
290296
Array
291297
(
292-
[device_type] => mobile
298+
[device_type] => tv
293299
)
294300
```
295301

296302
### Desktop Mode Detection
297303

298-
To detect mobile browser works in `Desktop Mode` use:
304+
To detect if mobile browser works in `Desktop Mode` use:
299305

300306
```php
301307
<?php
@@ -353,7 +359,7 @@ print_r($result);
353359
Returns:
354360

355361
```
356-
{"os_type":"mobile","os_family":"macintosh","os_name":"iOS","os_version":6,"os_title":"iOS 6","device_type":"mobile","browser_name":"Chrome","browser_version":78,"browser_title":"Chrome 78","browser_chrome_original":1,"browser_firefox_original":0,"browser_safari_original":0,"browser_chromium_version":78,"browser_gecko_version":0,"browser_webkit_version":0,"browser_android_webview":0,"browser_ios_webview":0,"browser_desktop_mode":0}
362+
{"os_type":"mobile","os_family":"macintosh","os_name":"iOS","os_version":6,"os_title":"iOS 6","device_type":"mobile","browser_name":"Chrome","browser_version":78,"browser_title":"Chrome 78","browser_chrome_original":1,"browser_firefox_original":0,"browser_safari_original":0,"browser_chromium_version":78,"browser_gecko_version":0,"browser_webkit_version":0,"browser_android_webview":0,"browser_ios_webview":0,"browser_desktop_mode":0,"64bits_mode":0}
357363
```
358364

359365
## Benchmarking Tests
@@ -362,27 +368,7 @@ Benchmarking was performed on a low-level shared hosting.\
362368
Test server configuration: RedHat Linux + LiteSpeed + PHP Extension.\
363369
Test conditions based on collection of random ~446000 non repeated real life User-Agent strings.
364370

365-
Recognition performance in the different PHP versions (Requests Per Second):
366-
367-
`Benchmark PHP 5.3:`
368-
369-
```
370-
getAll: ~ 5300 rps
371-
getOS: ~ 24000 rps
372-
getBrowser: ~ 5900 rps
373-
getDevice: ~ 16000 rps
374-
```
375-
376-
`Benchmark PHP 5.6:`
377-
378-
```
379-
getAll: ~ 6300 rps
380-
getOS: ~ 31000 rps
381-
getBrowser: ~ 7600 rps
382-
getDevice: ~ 19000 rps
383-
```
384-
385-
`Benchmark PHP 7.3:`
371+
Recognition performance in PHP 7.3 (Requests Per Second):
386372

387373
```
388374
getAll: ~ 31000 rps
@@ -395,7 +381,7 @@ getDevice: ~ 70000 rps
395381

396382
The MIT License (MIT)
397383

398-
Copyright (c) 2020 Artem Murugov
384+
Copyright (c) 2020-2021 Artem Murugov
399385

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

0 commit comments

Comments
 (0)