Web Development: Using WURFL to identify the Clients’s device

Sometimes in web-development, it is needed to identify the connecting device, if it is a mobile phone, a tablet or a normal desktop browser.

This is possible by inspecting the HTTP_USER_AGENT parameter -part of the HTTP header- which has some information about the client’s browser, connecting device and operating system.

Anyway; the HTTP_USER_AGENT parameter is a mess, there are no specifications about how the browser should formulate the HTTP_USER_AGENT string and you can never tell from the string signature the supported features on the connecting device. Sometimes it is needed to know if  the connecting device support HTML5 and J2ME? , does this device have a QWERTY keyboard …etc.

To establish this; the USER_AGENT string signature is used to identify the device-browser combination, then a database is queried for the features supported for the identified device.

WURFL is an XML database and a library that can tell the developer what features to expect in the connecting device. It is an open source project that has libraries available in PHP, Java and Python. Plus a huge XML Database for each device-browser and it capabilities.

I created this sample site http://ip.maksoft.ch to show what WURFL knows about your connecting device.

Among the features stored in the WURFL XML database are:

  • J2ME support.
  • MMS support.
  • Viewport html tag support.
  • Pointing methods .
  • … etc

For example :

  • To identify if the user is connecting by phone, use the “is_wireless_device” feature.
  • To identify iPhones, iPads or iPod-touch, test for “brand_name”==”Apple”.

One of the things missing from the WURFL database, is location awareness features. i.e. Does the device has a GPS in it or not. There are some more WURFL plugins available for providing Icons for the devices and for using a database instead of a file-based cache.

Among the things I noticed upon using Opera Mobile browsers, is it hides your device model and hence WURFL will only provide data based on Opera and OS capabilities.

This is very useful if you intend to develop mobile or tablet aware websites.