Parsing mobile phone user agent string , good solu

2019-06-17 06:49发布

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.

8条回答
趁早两清
2楼-- · 2019-06-17 07:34

I use this PHP class in my projects:

http://code.google.com/p/mobileesp/source/browse/PHP/mdetect.php

It works very very well. It's simple, no DB, no remote API, no huge files.

查看更多
Ridiculous、
3楼-- · 2019-06-17 07:35

recently tried to solve a similiar problem, its much better to use an open source or off the shelf solution for this, as you will be in a battle to keep your code upto date etc. personally i'd try the free version, if it does what you need stick with it.

you colud try something like if( strstr($_SERVER['HTTP_USER_AGENT'],'Android') || strstr($_SERVER['HTTP_USER_AGENT'],'webOS') || strstr($_SERVER['HTTP_USER_AGENT'],'iPhone') || strstr($_SERVER['HTTP_USER_AGENT'],'iPod') ){ //mobile user }

if you just need to know the os, it detects the most popular. then add others as appropriate, for nokia etc.

http://www.concrete5.org/community/forums/customizing_c5/mobile-version/ seems to be a more complete list

hope this helps.

查看更多
登录 后发表回答