php – 检测移动设备或平板电脑设备

我的目标是建立一个移动网站(用于手机和平板电脑)和一个基于wordpress的响应式桌面网站.我想要最简单的方法来实现万无一失的设备检测.

移动网站将拥有许多功能,这些功能只会使触控设备受益,并将为手机和平板电脑定制设计.桌面网站将完全不同(具有相同的页面,但具有额外的内容),并且将完全响应,以防任何设备滑过检测.

我有一个将检测触摸设备并重定向到另一个页面的衬垫,但它似乎太简单,不能成为设备检测的万无一失的方法.这有多傻瓜?它适用于WindowsAndroid设备以及iOS吗?

这是我第一次做这样的网站,并不确定这将是多么有效:

<!-- Redirect to the mobile index page if we're on a touch device -->
<script>if( 'ontouchstart' in window ) window.location = 'mobile.html';</script>

解决方法

您可以使用 mdetect(移动检测)库为您执行此操作.它以多种语言编写,可以检测Windows,Android,iOS等.请务必阅读文档.

> PHP Version
> JavaScript Version

请注意,JavaScript版本包含此警告:

// WARNING: 
//   These JavaScript-based device detection features may ONLY work 
//   for the newest generation of smartphones,such as the iPhone,//   Android and Palm WebOS devices.
//   These device detection features may NOT work for older smartphones 
//   which had poor support for JavaScript,including 
//   older BlackBerry,PalmOS,and Windows Mobile devices. 
//   Additionally,because JavaScript support is extremely poor among 
//   'feature phones',these features may not work at all on such devices.
//   For better results,consider using a server-based version of this code,//   such as Java,APS.NET,PHP,or Ruby.

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...