在PHP和jQuery中检测移动设备和馈送页面的标准实践 [英] Standard Practices in Detecting Mobile Devices and Feeding Pages in PHP and jQuery
本文介绍了在PHP和jQuery中检测移动设备和馈送页面的标准实践的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我看到网站的移动版本通常以"m"开头. (例如 http://m.accuweather.com ).我想将移动用户重定向到http://m.mysite.com
,以便显示其他页面.
I see that mobile versions of websites often begin with an "m." (e.g. http://m.accuweather.com). I'd like to redirect my mobile users to http://m.mysite.com
so that I can display a different page.
- 向移动设备提供网站的移动版本的标准做法是什么?是否可以在服务器端(如果可能的话)或客户端上检测设备的类型?
- 如何检测移动设备是否正在服务器端(使用PHP)和客户端(使用jQuery)上访问网站?
- 是否可以检测它是否是Apache级别的移动设备?还是我必须经常使用PHP脚本来检查它是否是移动设备并重定向到页面的适当版本?
推荐答案
最简单的方法是检查用户代理,该代理可通过$_SERVER['HTTP_USER_AGENT']
获得.尽管客户端可以发送任何字符串,但如果不是(并且这样做的话,人们通常不会假装他们是移动浏览器)(如果这样做,这不是您的问题).
The easiest way is checking the user agent, available via $_SERVER['HTTP_USER_AGENT']
. While clients can send any string, people usually do not pretend to be a mobile browser if they aren't (and if they do so - not your problem).
这篇关于在PHP和jQuery中检测移动设备和馈送页面的标准实践的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文