PHP 检测用户设备

使用专门用于检测用户设备信息的开源项目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;
……

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值