Detecting mobile devices

XHTML MP

You can get the Open Mobile Alliance document describing the XHTML MP 1.1 version here (pdf).

Content types

The same document describes that XHTML MP pages should be served with the "application/vnd.wap.xhtml+xml" or "application/xhtml+xml" content types. In practice, however, "text/html" seems to serve better. In fact when I use the "application/vnd.wap.xhtml+xml", my SonyEricsson K510i refuses to show me the content of the page.

With mobile web being is all the rage these days, detecting mobile devices could be important.

WAP2 standard sets XHTML MP (Mobile Profile) as a markup language, and, more importantly for the purpose of this article, defines that the client agent should have an Accept header with the "application/vnd.wap.xhtml+xml" value. We will be using that requirement to identify a presumably mobile device accessing our script:

<?php
// ...

if ( strpos($_SERVER['HTTP_ACCEPT'],'application/vnd.wap.xhtml+xml')!==false )
{
  // It's a mobile device, do something appropriate
}

// ..
?>

photo is a part of the Alpha Orionis and does freelance too.

I recommend

Freakonomics Getting Things Done Getting Real Steve Krug: Don't make me think

I'm using

Mac Coda RoR

Hosting is kindly provided by