使用专门用于检测用户设备信息的开源项目Mobile Detect
原生PHP:
<?php
// 引入类库
require_once 'Mobile_Detect.php';
// 实例化
$detect = new Mobile_Detect;
/**
* 查询设备的类型
*/
// 是否为移动设备(包含手机与平板)
if ( $detect->isMobile() ) {
// 是移动设备
}
/**
* 查询设备的操作系统
*/
// 是否为iOS系统
if( $detect->isiOS() ){
// 是iOS系统
}
/**
* 查询浏览器
*/
if( $detect->isChrome() ){
// 是Chrome浏览器
}
/**
* 查询品牌
*/
if( $detect->isSony() ){
// 是索尼大法
}
这里是几个简单的示范,Mobile_Detect()这个类还可以查询设备类型,甚至包括Kindle!
具体可以看一下文档:http://demo.mobiledetect.net/
ThinkPHP框架下使用Mobile_Detect
和其他的第三方类库一个用法:
1、将Mobile_Detect整个包放到Vendor文件夹下
2、使用Vendor()引入
<?php
……
Vendor("MobileDetect.Mobile_Detect");
$detect = new \Mobile_Detect;
……