解析手机用户代理字符串,好的解决方案还是库? [英] Parsing mobile phone user agent string , good solution or library?

查看:107
本文介绍了解析手机用户代理字符串,好的解决方案还是库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要求: 通过从浏览器中解析用户代理字符串来找出用户正在使用的电话.(在PHP中) 例如.诺基亚1100,三星D900.

Requirement : To find out which phone the user is using by parsing the user agent string from his browser.( in PHP ) eg. Nokia 1100 , Samsung D900 .

是否有一个很好的库,其中包含足够的电话销售商和型号数据库?

Is there a good library available with sufficient database of phone vendors and models ?

我找到了一些解决方案,需要您对相同的看法:

Some solutions I found, need your views on the same :

i)手机检测: https://www.handsetdetection.com -付费订阅

ii) WURFL - http://wurfl.sourceforge.net/

iii)自己的解决方案-我有一个由电话制造商和型号组成的小型数据库,但必须在我的代码中为用户代理字符串添加量身定制的检查,以与数据库进行/fuzzy匹配用户代理字符串格式在制造商之间不一致.

iii) Own solution - I have a small database of phone makers, and models , but will have to add tailormade checks for user agent strings in my code to match /fuzzy match against the database as user agent string format is not consistent across makers.

我们创建了一个量身定制的解决方案,该解决方案混合了正则表达式以将标准用户代理(例如iOS,Android,Blackberry和WURFL)解析为其他手机(如symbian,j2me,bada等)的后备机制.

We created a tailormade solution which was a mix of regular expressions to parise standard user agents like iOS,Android,Blackberry,and WURFL as a fallback mechanism for other phones like symbian,j2me,bada etc.

在添加数据库/缓存(MySql,memcached,mongodb等)后,WURFL的运行效果非常好,该数据库/缓存已作为核心代码库中的设置存在.尽管您必须每隔几周使用最新版本的WURFL手机xml数据库更新/同步wurfl信息随时了解最新发布的手机的规格.

WURFL works great after adding database/cache (MySql,memcached,mongodb etc) which already exists as a setting in the core codebase.Though you have to update/sync wurfl information with newest version of WURFL handset xml database every few weeks to stay updated with specs of new released mobile phones.

推荐答案

首先,我会说KISS(保持简单,愚蠢)是出于某种原因而被广泛使用的表达方式.首先,我将仔细检查我的业务需求,然后查看我真正需要多少设备信息以及将其用于什么用途.也许您只需要查看客户端正在使用哪个渲染引擎?

First, I would say KISS (Keep It Simple, Stupid) which is a widely used expression for a reason. I would start off by double checking my business needs and see how much device information I really need and what I am going to use it for. Maybe you only need to see which rendering engine the client is using?

第二,您应该考虑解析时间.如果最终使用了 WURFL 并在您的网站上解析该XML,则需要解析400  000检查设备信息时,使用+行XML.当然,您可以将XML放入本地索引数据库中,但这还需要一些维护脚本才能将更新后的XML中的数据与数据库同步.

Second, you should consider the parsing time. If you end up using i.e. WURFL and parsing that XML on your site, you would need to parse 400 000+ lines of XML when checking for device information. Of course, you could put the XML into a local indexed database, but that would also require some maintenance scripts to synchronize the data in the updated XML with the database.

第三(但也许应该是第一?)正在考虑解决方案的成本/收益.如果您在该网站上赚钱,将一些责任留给合作伙伴可能是明智的.像 handsetdetection.com 这样的托管服务似乎能够以不算太贵的成本提供高流量.另一个好处是,他们负责维护自己的存储库,如果他们的服务不够好,他们可能会失去客户.从理论上讲,OpenSource社区可以休假4个月,并且在此期间将无法维持解决方案(我真的不认为应该为此担心;-)

Third (but maybe it should be first?) is considering the cost/benefit of the solution. If you make money on the site, it might be smart to leave some responsibility on a partner. A hosting service like handsetdetection.com seems capable of delivering high traffic at a not-so-terrifying cost. Another benefit is that they are responsible for maintaining their own repository and could lose customers if their service isn't good enough. The OpenSource community could theoretically go on a 4 month vacation and the soulution wouldn't be maintained in that period (I really wouldn't think that should be anything to worry about ;-)

不知道您的确切需求,我会像这样优先处理它:

Not knowing your exact needs, I would prioritize it like this:

  1. 使用尽可能简单的解决方案,即检测移动浏览器
  2. 像WURFL一样使用OpenSource.我只是喜欢开源解决方案:-)
  3. 如果您的业务需要保证稳定性和数据质量,则应让专业人员处理;-)

这篇关于解析手机用户代理字符串,好的解决方案还是库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆