所属分类:PHP实例-函数/算法,常用实例教程
使用 Mobile Detect提供了多种检测函数,可以轻松检测设备类型,基本上市面上的手机品牌、操作系统、版本、浏览器类型等等信息。
以下举例说明:
require_once 'Mobile_Detect.php'; $detect = new Mobile_Detect; $detect->isMobile(); // 是否为移动设备 $detect->isTablet(); // 是否为平板设备 $detect->isIphone(); //是否为苹果手机 $detect->isSamsung(); // 是否为三星手机 $detech->isiOS(); // 是否为iOS操作系统 $detect->version('Android'); // 获取当前Android系统的版本更多方法函数请查看演示demo 实际应用中例子:用户使用PC浏览器访问站点http://www.sucainiu.com打开的是通用PC版网站首页,而如果用户使用手机或者平板电脑访问站点http://www.sucainiu.com时,这时Mobile Detect检测到用户使用的终端为移动设备,然会会跳转到http://m.erdangjiade.com,即移动版站点上。
if($detect->isMobile()){ header('http://m.sucainiu.com', true, 301); }