Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 14c7112

Browse files
committed
Version 1.1 (release)
1 parent b9a4360 commit 14c7112

File tree

9 files changed

+361
-34
lines changed

9 files changed

+361
-34
lines changed

‎README.md

Lines changed: 67 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
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 100 browsers types and ~ 58 OS types.\
5+
Uses a simple and fast algorithm to accurate detection more than 120 browsers types and ~ 58 OS types.\
66
For most commonly browsers parsing process tooks less than 0.0005 second even on low-level shared hosting.\
77
In the case of very unusual User-Agents recognized time is less than 0.0008 second for 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.\
@@ -38,7 +38,7 @@ Second argument (optional) may contains 'JSON' if you want to get returned resul
3838
```php
3939
<?php
4040
require_once('BrowserDetection.php');
41-
$Browser = new BrowserDetection();
41+
$Browser = new foroco\BrowserDetection();
4242

4343
$useragent = $_SERVER['HTTP_USER_AGENT'];
4444

@@ -66,6 +66,17 @@ $result = $Browser->getAll($useragent, 'JSON');
6666
?>
6767
```
6868

69+
The library class `BrowserDetection` also contains special method `setTouchSupport()` (optional, available from version 1.1).\
70+
This method is necessary to detect mobile browsers in `Desktop Mode` condition (Android and iOS).\
71+
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:
73+
74+
```javascript
75+
if (('ontouchstart' in window) || window.DocumentTouch && document instanceof DocumentTouch) {
76+
// Touch Event detected
77+
}
78+
```
79+
6980
## Description for returned variables
7081

7182
**OS Type** (`os_type`)\
@@ -146,6 +157,10 @@ Returns `1` number if Android Webview mode detected or returns `0` if it's not.
146157
**Browser iOS Webview** (`browser_ios_webview`)\
147158
Returns `1` number if iOS Webview mode detected or returns `0` if it's not.
148159

160+
**Browser Desktop Mode** (`browser_desktop_mode`)\
161+
Returns `1` number if mobile browser works in `Desktop Mode` or returns `0` if it's not detected.\
162+
`setTouchSupport()` method should call for `Desktop Mode` detection if browser supports Touch events.
163+
149164
## Usage Examples
150165

151166
See follow examples to understand library usage use cases.
@@ -157,7 +172,7 @@ To detect all possible environment data use:
157172
```php
158173
<?php
159174
require_once('BrowserDetection.php');
160-
$Browser = new BrowserDetection();
175+
$Browser = new foroco\BrowserDetection();
161176

162177
$useragent = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.4150.0 Iron Safari/537.36';
163178
$result = $Browser->getAll($useragent);
@@ -187,6 +202,7 @@ Array
187202
[browser_webkit_version] => 0
188203
[browser_android_webview] => 0
189204
[browser_ios_webview] => 0
205+
[browser_desktop_mode] => 0
190206
)
191207
```
192208

@@ -197,7 +213,7 @@ To parse only OS data use:
197213
```php
198214
<?php
199215
require_once('BrowserDetection.php');
200-
$Browser = new BrowserDetection();
216+
$Browser = new foroco\BrowserDetection();
201217

202218
$useragent = 'Mozilla/5.0 (Android 8.1.0; Tablet; rv:68.6.0) Gecko/68.6.0 Firefox/68.6.0';
203219
$result = $Browser->getBrowser($useragent);
@@ -225,7 +241,7 @@ To parse only browser data use:
225241
```php
226242
<?php
227243
require_once('BrowserDetection.php');
228-
$Browser = new BrowserDetection();
244+
$Browser = new foroco\BrowserDetection();
229245

230246
$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';
231247
$result = $Browser->getBrowser($useragent);
@@ -249,6 +265,7 @@ Array
249265
[browser_webkit_version] => 0
250266
[browser_android_webview] => 0
251267
[browser_ios_webview] => 0
268+
[browser_desktop_mode] => 0
252269
)
253270
```
254271

@@ -259,7 +276,7 @@ To parse only device type data use:
259276
```php
260277
<?php
261278
require_once('BrowserDetection.php');
262-
$Browser = new BrowserDetection();
279+
$Browser = new foroco\BrowserDetection();
263280

264281
$useragent = 'MEmpresas/20180706 CFNetwork/808.2.16 Darwin/17.4.0';
265282
$result = $Browser->getBrowser($useragent);
@@ -276,14 +293,56 @@ Array
276293
)
277294
```
278295

296+
### Desktop Mode Detection
297+
298+
To detect mobile browser works in `Desktop Mode` use:
299+
300+
```php
301+
<?php
302+
require_once('BrowserDetection.php');
303+
$Browser = new foroco\BrowserDetection();
304+
305+
$useragent = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36';
306+
$Browser->setTouchSupport(); // Call if Touch events detected in browser by JavaScript code ('ontouchstart' in window)
307+
$result = $Browser->getBrowser($useragent);
308+
print_r($result);
309+
?>
310+
```
311+
312+
Returns:
313+
314+
```
315+
Array
316+
(
317+
[os_type] => mobile
318+
[os_family] => android
319+
[os_name] => Android
320+
[os_version] => 0
321+
[os_title] => Android
322+
[device_type] => mobile
323+
[browser_name] => Chrome
324+
[browser_version] => 81
325+
[browser_title] => Chrome 81
326+
[browser_chrome_original] => 1
327+
[browser_firefox_original] => 0
328+
[browser_safari_original] => 0
329+
[browser_chromium_version] => 81
330+
[browser_gecko_version] => 0
331+
[browser_webkit_version] => 0
332+
[browser_android_webview] => 0
333+
[browser_ios_webview] => 0
334+
[browser_desktop_mode] => 1
335+
)
336+
```
337+
279338
### Detect All (JSON)
280339

281340
To pasre all possible environment data and returns JSON format string:
282341

283342
```php
284343
<?php
285344
require_once('BrowserDetection.php');
286-
$Browser = new BrowserDetection();
345+
$Browser = new foroco\BrowserDetection();
287346

288347
$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';
289348
$result = $Browser->getAll($useragent);
@@ -294,7 +353,7 @@ print_r($result);
294353
Returns:
295354

296355
```
297-
{"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}
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}
298357
```
299358

300359
## Benchmarking Tests

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /