homepage Welcome to WebmasterWorld Guest from 54.225.1.70
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Visit PubCon.com
Home / Forums Index / Hardware and OS Related Technologies / Smartphone, Wireless, and Mobile Technologies
Forum Library, Charter, Moderators: bakedjake

Smartphone, Wireless, and Mobile Technologies Forum

    
Detecting if user-agent corresponds to mobile phone
Jakotsu




msg:3282431
 4:55 am on Mar 15, 2007 (gmt 0)

Hi,
Is it OK to assume that the user is on a mobile phone as long as the user agent string contains the "MIDP" and/or "CLDC" strings?

Basically, I need to disable Javascript when the user is on a mobile device, because most phones don't support Javascript at all.

 

bill




msg:3282483
 6:48 am on Mar 15, 2007 (gmt 0)

No. If I browsed your site with my phone from DoCoMo then the user agent [nttdocomo.co.jp] would not contain either of those strings.

phranque




msg:3282490
 7:06 am on Mar 15, 2007 (gmt 0)

the user agent for my treo 700p is:
Mozilla/4.0 (compatible; MSIE 6.0; Windows 98; PalmSource/Palm-D052; Blazer/4.5) 16;320x320

Jakotsu




msg:3283187
 9:42 pm on Mar 15, 2007 (gmt 0)

Well I'm now using this code that should detect properly most mobile brands:

/* Return TRUE if user is using mobile phone browser */
function isMobile(){
$useragent = $_SERVER['HTTP_USER_AGENT'];
// Standard vendor-model/version user agents
if (preg_match('/^((ACER¦Alcatel¦AUDIOVOX¦BlackBerry¦CDM¦Ericsson¦LG\b¦LGE¦Motorola¦MOT¦NEC¦Nokia¦Panasonic¦QCI¦SAGEM¦SAMSUNG¦SEC¦Sanyo¦Sendo¦SHARP¦SIE¦SonyEricsson¦Telit¦Telit_Mobile_Terminals¦TSM)[- ]?([^\/\s\_]+))(\/(\S+))?/', $useragent)){
return true;
}else{
return false;
}
}

[edited by: engine at 9:33 am (utc) on Mar. 16, 2007]

bill




msg:3283482
 6:47 am on Mar 16, 2007 (gmt 0)

That won't pick up most of the phones in my half of the world, nor would it pick up phranque's Treo.

Jakotsu




msg:3285997
 7:12 am on Mar 19, 2007 (gmt 0)

Well the most important manufacturers are included on that list... if you know a better way to detect a mobile phone, feel free to share it here in this forum.

bostonBeans




msg:3287773
 10:17 pm on Mar 20, 2007 (gmt 0)

Bill, does your phone and phranque's Treo support javascript? If so, it sounds like they should be left out of the list Jakotsu is trying to filter anyway.

phranque




msg:3287915
 1:29 am on Mar 21, 2007 (gmt 0)

Bill, does your phone and phranque's Treo support javascript?
If so, it sounds like they should be left out of the list Jakotsu is trying to filter anyway.

good point, bB!
i forgot to even check that and Blazer 4.5 supports ECMAscript (JavaScript 1.5)

bill




msg:3287947
 2:11 am on Mar 21, 2007 (gmt 0)

Bill, does your phone and phranque's Treo support javascript?

My personal phone doesn't, but some in that list I linked to do. And that's just one carrier in Japan. There are others. Then you have China, Korea, etc.

cmarshall




msg:3311832
 6:57 pm on Apr 15, 2007 (gmt 0)

The answer to the question posed is WURFL [wurfl.sourceforge.net], which is a fairly simple (but large) XML flatfile database that has been compiled by an Italian chap who works for OpenWave.

With a couple of lookup utilities, this database will match the user-agent of your phone to a set of capabilities. This means that if you have a phone that can handle WML 1.1, but not GIF files, you can feed it 1.1 pages with WBMP files.

It took me a while to get it going. Like so much of this kind of thing, documentation is a bit...sparse, but it's fairly easy to implement.

The developers prefer using Java to implement it, but there is a PHP [wurfl.sourceforge.net] implementation of it, and that's what I got going.

The biggest problem is the cache. It gets pretty big, quickly. At that size, I'm not so sure it really buys you much, as it will take PHP as long to look something up in the cache as it will to load the XML file.

It also exhausted the PHP memory allocation on my server.

I'm currently not using the cache, but there's a lot of stuff on it, written by the chap who did the PHP implementation. I'll have to see if I can make it work. He swears by it.

In any case, if you want to identify your device, WURFL seems to be the way to do it. It has achieved a great deal of acceptance, and appears regularly in scholarly writings on the subject.

[edited by: encyclo at 7:06 pm (utc) on April 15, 2007]
[edit reason] thread splice and tidying up [/edit]

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Hardware and OS Related Technologies / Smartphone, Wireless, and Mobile Technologies
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved