如何检测移动设备,让用户代理信息发送并保存到服务器上的数据库,只有一次?

时间:2022-06-20 01:38:45

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.

我正在制作一个移动网站,有两个版本,比如m.facebook.com和touch.facebook.com,我想重定向到不同的手机上。我用的是WURFL设备检测。

So for example m.html5version.com should be delivered to all HTML5 supported devices and m.mobileversion.com should deliver to all other mobiles.

例如,mhtml5version.com应该交付给所有HTML5支持的设备,mmobileversion.com应该交付给所有其他手机。

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.

因此,我需要一种方法来第一次检测设备和浏览器,使用任何服务器端或客户端方法。当任何用户将打开网站第一次设备然后一个脚本应该运行一次收集的信息设备和浏览器和应该保存在我现有的WURFL数据库的信息,所以下次当任何用户将来自相同的设备那么他将重定向到触摸或移动版网站根据设备。

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

Android 1.6不支持HTML5,仍在使用中。所以我想把所有的Android 1.6设备重定向到mmobileversion.com而不是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.

在网站的触摸版本中,我使用的是HTML 5标签,比如

3 个解决方案

#1


22  

see below link, this will perfectly suitable for your need

请看下面的链接,这将非常适合您的需要

http://detectmobilebrowser.com

below is one more script :

下面是另一个脚本:

http://detectmobilebrowsers.mobi

#2


4  

You might want to look into jQuery's take on this, since it's interesting.

你可能会想看看jQuery的这个,因为它很有趣。

In addition to detecting the browser, they detect browser features:

除了检测浏览器之外,它们还检测浏览器的特性:

http://api.jquery.com/jQuery.browser/

http://api.jquery.com/jQuery.browser/

http://api.jquery.com/jQuery.support/

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.

此外,请记住,一些移动用户不希望被重定向到移动优化设备。就我而言,当一个网站检测到我的iPad是一个移动设备,并且发送给我(没有任何可能去覆盖它)到一个我甚至不想用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.

一般来说,如果标准站点编码正确,iOS和Android设备将会很高兴地使用它。其他手机也在迅速消亡。

#3


0  

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.

只要检测并保存数据一次,您就可以设置一个cookie来记录您已经完成检测的事实。然后,下次加载页面时,检查cookie是否存在——如果不存在,那么调用检测函数并记录到数据库。如果你找到了cookie,那么你就知道你已经收集了数据,你可以跳过这一步。

http://www.quirksmode.org/js/cookies.html

http://www.quirksmode.org/js/cookies.html

#1


22  

see below link, this will perfectly suitable for your need

请看下面的链接,这将非常适合您的需要

http://detectmobilebrowser.com

below is one more script :

下面是另一个脚本:

http://detectmobilebrowsers.mobi

#2


4  

You might want to look into jQuery's take on this, since it's interesting.

你可能会想看看jQuery的这个,因为它很有趣。

In addition to detecting the browser, they detect browser features:

除了检测浏览器之外,它们还检测浏览器的特性:

http://api.jquery.com/jQuery.browser/

http://api.jquery.com/jQuery.browser/

http://api.jquery.com/jQuery.support/

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.

此外,请记住,一些移动用户不希望被重定向到移动优化设备。就我而言,当一个网站检测到我的iPad是一个移动设备,并且发送给我(没有任何可能去覆盖它)到一个我甚至不想用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.

一般来说,如果标准站点编码正确,iOS和Android设备将会很高兴地使用它。其他手机也在迅速消亡。

#3


0  

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.

只要检测并保存数据一次,您就可以设置一个cookie来记录您已经完成检测的事实。然后,下次加载页面时,检查cookie是否存在——如果不存在,那么调用检测函数并记录到数据库。如果你找到了cookie,那么你就知道你已经收集了数据,你可以跳过这一步。

http://www.quirksmode.org/js/cookies.html

http://www.quirksmode.org/js/cookies.html