WURFL

Introduction

Providing a website which works on both desktop computers and mobile devices

One common problem in web development is to ensure that your site is usable on both desktop computers and mobile devices, such as mobile phones. A related issue is that, even if you are aiming only at phones, you will probably want to make your site viewable across a wide range of different models running different operating systems, such as Android, iPhone OS and Symbian. There are a number of reasons why this might require extra effort.

What can we do about this?

User-agent detection

Each browser sends a so-called user agent string which is a unique description identifying the browser, version and operating system. For example for this browser it is

CCBot/1.0 (+http://www.commoncrawl.org/bot.html) 
We can obtain the user agent string quite easily in PHP:
<?php
$a = $_SERVER['HTTP_USER_AGENT'];
echo "The user agent is " .$a; 
?>
Then, we can generate different code for the website depending on the user agent string.

There is a remaining problem with this approach, however: there are many different mobile devices and browsers and clearly it would be a big job to try and test for all. This is where the WURFL comes in.

The WURFL: A repository of device capabilities

The WURFL (see here) is "an XML configuration file which contains information about capabilities and features of several wireless devices" (wurfl.sourceforge.net). In other words, the WURFL is an XML file which maps individual mobile devices to their capabilities (e.g. do they support XHTML?). You can write a web application which queries this XML file to look up the capabilities of a given mobile device.

WURFL can be used from a range of languages such as PHP and Java (see the WURFL site). From PHP the following procedure is performed:

Example of using the WURFL from PHP

See here for a full example. Here is an explanation of each line of code:

More on Capabilities

The most important concept in the WURFL is the capability. A capability is a particular feature that the mobile device may or may not support, and we can query any capability. The way in which we reference a capability is shown above.

Full documentation of all capabilities is available here. There are a number of capability categories, which are described in detail on the WURFL site; they include such things as:

Most capabilities give either a true or a false value, but a few return text. For example the mobile_browser capability returns a string (i.e. text) representing the browser being used on the mobile device.

Some specific examples: