Welcome to WebmasterWorld Guest from 23.20.230.24

Forum Moderators: bakedjake

Message Too Old, No Replies

Detecting if user-agent corresponds to mobile phone

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

10+ Year Member



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.

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

WebmasterWorld Administrator bill is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



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.
7:06 am on Mar 15, 2007 (gmt 0)

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



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
9:42 pm on Mar 15, 2007 (gmt 0)

10+ Year Member



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]
6:47 am on Mar 16, 2007 (gmt 0)

WebmasterWorld Administrator bill is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



That won't pick up most of the phones in my half of the world, nor would it pick up phranque's Treo.
7:12 am on Mar 19, 2007 (gmt 0)

10+ Year Member



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.
10:17 pm on Mar 20, 2007 (gmt 0)

10+ Year Member



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.
1:29 am on Mar 21, 2007 (gmt 0)

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



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)

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

WebmasterWorld Administrator bill is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



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.
6:57 pm on Apr 15, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



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]

 

Featured Threads

Hot Threads This Week

Hot Threads This Month