(EDITOR'S NOTE: This is an article in progress - please check back for updates)

Modern, mobile, social. It's a theme for RavenNuke™ 3.0. The mobile part is especially interesting. Spasticdonkey and others have been looking into mobile theme support, which raised my question: what is the best way to detect mobile devices? A little research yielded several options that fall into 2 categories: locally installed scripts that parse the browser's HTTP Header (mainly the User-Agent) and cloud / hosted services with a device description repository (DDR) - a database of device information - which can usually be installed locally for a higher price.

Which approach is right for your site? That depends on a number of factors:

HTTP Header Parsing

First, let's clarify that the information used to detect a device is passed from the browser through the HTTP header. This includes:

User-Agent ($_SERVER["HTTP_USER_AGENT"])

X-Wap-Profile ($_SERVER["HTTP_X_WAP_PROFILE"])

Profile ($_SERVER["HTTP_PROFILE"])

Opt

X-Wap-Profile and Profile contain and Opt may contain a reference (technically a namespace reference) to an Open Mobile Alliance UAProf document (an XML file) which contains details about the connected device. However, the UAProf standard is not supported by all mobile devices. Furthermore, a mobile device can have multiple UAProf profiles.

Assuming PHP is able to retrieve the UAProf device information, what does it contain? UA Prof information is grouped into components:

Unless your site needs to differentiate based on this information, the inconsistencies, complexity and overhead might not add value. Although the screen size might be useful for sizing images, it only represents the maximum size supported by the device - not the current zoom level or orientation. So, several approaches simply use the User Agent to detect whether or not a device is mobile. The tools parse data from the HTTP User-Agent attribute to determine if a device is mobile and, in some cases, if a device is a tablet. They can usually detect the operating system and the browser.

Device Description Repositories

Several solutions match HTTP Header information against a database of device information or use the UAProf information provided by the manufacturer. In some cases, the Device Description Repository (DDR) might be populated from the manufacturer UAProf information, either in advance or on-the-fly. At least one solution only queries the manufacturers information (and could be used to build a DDR on the fly), so it can also be considered a DDR. Although DDR information is more detailed than simply parsing the HTTP headers, that detail information might be less consistent, especially if it is not augmented by human editors as the vendor-supplied information varies significantly.