Forum Moderators: bakedjake
/* Return TRUE if user is using mobile phone browser */
[edited by: engine at 9:33 am (utc) on Mar. 16, 2007]
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;
}
}
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]