2007-12-09

Mobile Browser Detection in PHP

From Russell Beattie:

"I use the fastest method of matching strings in PHP, which is strpos() - it returns False if it doesn't find a match, or the number of the first character in that match. It's fast, and you'll see in the code below, chainable using the || (or) comparison operator. As soon as a match comes up, it'll short circuit the rest of the code, making common user-agents faster to detect with a simple re-ordering. Also, you can mix and match headers to look at including remote address, etc. For Mowser, I also like to make sure that bots always see the mobile version as well, so I've included detection code for those user-agents (and one common IP) at the bottom."

2007-12-08

W3C mobileOK Checker [ALPHA]

Based on W3C mobileOK Basic Tests 1.0; see also http://www.w3.org/Mobile/ and http://www.w3.org/TR/mobile-bp/.

Should be helpful in making a site usable with mobes and other handheld devices. To get there will of course mean some (read: a lot) of extra work compared to serving only to desktop UAs and robots. But with some trickery (transforms) one should be able to spit out code from a single source for desktop, and from that single source, code that also renders moderately uniformly across handhelds, although clearly a lot has to be sacrificed (at least style-wise, see Default Delivery Context) compared to just serving to desktop.