-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
example.php
34 lines (23 loc) · 792 Bytes
/
example.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?php
/**
* Example using composer's autoloader.
*/
use Detection\MobileDetect;
require_once __DIR__ . '/../vendor/autoload.php';
$detect = new MobileDetect();
// This is optional. We scan for known $_SERVER variables.
// See: https://github.com/serbanghita/Mobile-Detect/issues/948#issuecomment-1800271108
$detect->setUserAgent('Mozilla/5.0 (iPad; CPU OS 14_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) GSA/248.1.504392274 Mobile/15E148 Safari/604.1');
$isMobile = false;
try {
$isMobile = $detect->isMobile();
} catch (\Detection\Exception\MobileDetectException $e) {
}
var_dump($isMobile);
$isTablet = false;
try {
$isTablet = $detect->isTablet();
var_dump($isTablet);
} catch (\Detection\Exception\MobileDetectException $e) {
}
var_dump($isTablet);