php检测移动端

现在开发网站项目时,经常都需要自动检测客户端是PC还是mobile。通过js判断是比较常用的方法,也有不少成熟的第三方库可用,比如Device.js,这是一个可以让你检测设备的平台、操作系统和方向的JavaScript库。

对于很多采用统一入口的PHP程序来说,通过入口文件完成移动端检测是比较便捷的方式,Mobile Detect:The lightweight PHP class for detecting mobile devices(including tablets) 库正好帮我们做了这方面工作。

简单介绍使用方法:

// Include and instantiate the class.
require_once 'Mobile_Detect.php';
$detect = new Mobile_Detect;

// Any mobile device (phones or tablets).
if ( $detect->isMobile() ) {
    // do something
}

Demo地址:Mobile Detect Demo
GibHub链接:MobileDetect

标签: device.js, mobiledetect, mobile

添加新评论