Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parsing mobile phone user agent string , good solution or library?

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) handsetdetection : https://www.handsetdetection.com - paid subscription

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

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.

UPDATE:

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.

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.

like image 422
DhruvPathak Avatar asked Mar 01 '12 12:03

DhruvPathak


People also ask

What is user agent parsing?

This information, gleaned directly from the User-Agent string itself (a process known as User-Agent parsing) typically includes browser, web rendering engine, operating system and device. Deeper information can be returned when the User-Agent string is mapped to an additional set of data about the underlying device.

What is user agent string?

A user agent is a piece of software that acts on behalf of a user, such as a web browser. A user agent string however is sent as an HTTP request header by the browser and identifies which operating system is being used, the browser version, and other information which is provided to the web server.

What does UA parser do?

ua-parser-js is used in apps and websites to discover the type of device or browser a person is using from User-Agent data. A computer or device with the affected software installed or running could allow a remote attacker to obtain sensitive information or take control of the system.

What is a user agent Python?

user_agents is a Python library that provides an easy way to identify/detect devices like mobile phones, tablets and their capabilities by parsing (browser/HTTP) user agent strings. The goal is to reliably detect whether: User agent is a mobile, tablet or PC based device.


1 Answers

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?

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.

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. Use as simple a solution as possible, i.e. the solution from Detect Mobile Browsers
  2. Go OpenSource, like WURFL. I just love OpenSource solutions :-)
  3. If your business needs guaranteed stability and data quality, you should let the professionals handle it ;-)
like image 92
Bjørne Malmanger Avatar answered Oct 03 '22 05:10

Bjørne Malmanger