如何检测移动设备并获取用户代理信息发送并将该信息保存到服务器上的数据库中,仅一次?
是否有任何脚本来检查用户代理,然后将该信息发送并保存到服务器上的数据库中?
我正在制作具有 2 个版本的移动网站,例如 m.facebook.com 和 touch.facebook.com,我想重定向到不同的手机。我使用 WURFL 设备检测。
例如,m.html5version.com 应传送至所有支持 HTML5 的设备,而 m.mobileversion.com 应传送至所有其他移动设备。
所以我需要一种使用任何服务器端或客户端方法第一次检测设备和浏览器的方法。当任何用户第一次在设备上打开网站时,脚本应该运行一次,它应该收集有关设备和浏览器的信息,并将该信息保存在我现有的 WURFL 数据库中,因此下次任何用户来自同一设备时,他将根据设备重定向到触摸版或移动版网站。
因此,只有第一次在第一台设备上我想检测设备并保存信息。
有什么办法可以做到这一点吗?
例如
Android 1.6 不支持 HTML5,但仍在使用中。所以我想将所有 Android 1.6 设备重定向到 m.mobileversion.com 而不是 touch.mobileversion.com
并且在网站的触摸版本中我使用 HTML 5 标签,例如Android 1.6 不支持
Is there any script to check user agent then send and save that information to database on server?
I'm making mobile website with 2 versions like m.facebook.com and touch.facebook.com and I want to redirect to different mobiles. and I use WURFL device detection.
So for example m.html5version.com should be delivered to all HTML5 supported devices and m.mobileversion.com should deliver to all other mobiles.
So i need a way to detect device and browser 1st time using any server-side or client-side method. when any user will open the website first time on device then an script should run once it should collect the information about device and browser and should save the information in my existing WURFL database , so next time when any user will come from same device then he will redirect to touch or mobile version of website depending on device.
So only 1st time on 1st device I want to detect device and save the info.
Is there any way to do this?
For example
Android 1.6 doesn't have HTML5 support and still in use. So i want to redirect all Android 1.6 devices to m.mobileversion.com not to touch.mobileversion.com
And in touch version of website I'm using HTML 5 tags like <header>
, <footer>
, <nav>
etc which is not supported Android 1.6. So i want to detect the first device who will access the website from Android 1.6 device and because HTML5 is not supported in 1.6 so user agent should be saved in my database then I when next time any user will open the website in 1.6 it will redirect to lo-fi mobile version automatically, no detection should be needed 2nd time for any device.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
请参阅下面的链接,这将完全适合您的需求
http://detectmobilebrowser.com
下面是另一个脚本:
http://detectmobilebrowsers.mobi
see below link, this will perfectly suitable for your need
http://detectmobilebrowser.com
below is one more script :
http://detectmobilebrowsers.mobi
您可能想研究一下 jQuery 对此的看法,因为它很有趣。
除了检测浏览器之外,它们还检测浏览器功能:
http://api.jquery.com/jQuery。浏览器/
http://api.jquery.com/jQuery.support/
另外,请记住,某些移动用户不希望被重定向到移动优化设备。就我而言,当某个网站将我的 iPad 检测为移动设备并将我(没有任何可能覆盖它)发送到一个我什至不想用 iPhone 浏览的草率移动网站时,我非常讨厌它。
一般来说,如果编码正确,iOS 和 Android 设备将很乐意与标准站点一起使用。其他手机也很快就会消亡。
You might want to look into jQuery's take on this, since it's interesting.
In addition to detecting the browser, they detect browser features:
http://api.jquery.com/jQuery.browser/
http://api.jquery.com/jQuery.support/
Also, keep in mind that some mobile users don't want to be redirected to the mobile-optimized device. I, for one, positively hate it when a site detects my iPad as a mobile device and sends me (without any possibility to override it) to a sloppy mobile site that I wouldn't even want to browse with an iPhone.
iOS and Android devices, in general, will happily work with the standard site if it's coded properly. And other mobile phones are quickly dying.
至于只检测并保存一次数据,您可以设置一个cookie来记录您已经完成检测的事实。然后,下次加载页面时,检查 cookie 是否存在——如果不存在,则调用检测函数并将其记录到数据库中。如果您确实找到了 cookie,那么您就知道您已经收集了数据,并且可以跳过再次收集数据。
http://www.quirksmode.org/js/cookies.html
As far as only detecting and saving the data once, you can set a cookie to record the fact that you've already done the detection. Then the next time a page is loaded, check to see if the cookie exists -- if it doesn't, then call your detection function and record to the database. If you do find the cookie, then you know you've already collected the data and you can skip doing it again.
http://www.quirksmode.org/js/cookies.html