不言不语

您现在的位置是: 首页 >  PHP

PHP

移动设备检测类Mobile_Detect.php

2022-06-05PHP
Mobile_Detect.php是一个轻量级的开源移动设备检测的PHP Class。它使用User-Agent中的字符串,并结合 HTTP Header来检测移动设备环境。Mobile_Detect.php有一个非常完整的移动设备库,可以检测出所用的设备类型(包括操作系统类型,以及手机品牌等都能检测)和浏览器User-Agent的详细信息。

1、引入Mobile_Detect.php

1

require_once 'Mobile_Detect.php';

2、实例化Mobile_Detect类

1

$detect = new Mobile_Detect();

3、调用Mobile_Detect类里的方法和属性

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

//平板设备
if( $detect->isTablet()) {
}
//移动设备但非平板
if( $detect->isMobile() && !$detect->isTablet()) {
}
//IOS系统
if( $detect->isiOS()) {
}
//Android系统
if( $detect->isAndroidOS()) {
}
//WindowsPhone系统
if( $detect->isWindowsPhoneOS()) {
}


文章评论