So you want to deploy a mobile version of your website? You’ve thought about what your target users would do with a mobile version, written your content, created your design and developed your Flash or HTML, CSS and Javascript (if you haven’t done that yet, read this post instead). Now for the task that can seem most daunting to new mobile web developers — detecting devices and serving the correct version of your site. How do you ensure that users with mobile phones will see the mobile version and vice versa?
The answer: WURFL. The Wireless Universal Resource File (WURFL) is an open source project which collects information about all of the different mobile devices in use. It is constantly being updated, so as long as you keep your WURFL definitions up-to-date you don’t have to worry about your detection scripts not recognising new devices. By querying a WURFL database with your visitor’s User Agent string, you can not only determine whether the device they are using is a mobile device, but whether it has a touch screen, can make phone calls, is a tablet (iPad) and more.
It is reasonably straightforward to install a Tera-WURFL service on your PHP enabled web server. If download speed is critical for your website, it would be best to install Tera-WURFL on the same web server. But if you would prefer to avoid the installation process, feel free to use our quick and easy These Days implementation of Tera-WURFL.
It can be as simple as this:
<?php
require_once ('<a href="http://wurfl.thesedays.com/example/example.zip">TeraWurflRemoteClient.php</a>');
$wurflObj = new TeraWurflRemoteClient(
'http://wurfl.thesedays.com/webservice.php' );
$wurflObj->getCapabilitiesFromAgent(null, array('product_info'));
if ($wurflObj->getDeviceCapability("is_wireless_device")) {
// Show mobile website
} else {
// Show normal website
}
?>
Don’t forget to give your users a way of overriding automatic device detection. Even WURFL can get it wrong sometimes, and anyway some users prefer to view full sites on their mobile phones. The user is king!
We’re experiencing issues trying to access the WURLF webservices.php script today. Any ETA on getting it fixed? Thanks, Del
The hosted WURFL script is back online. Thanks!
Not a problem Del. Thanks for letting us know. We just had to update the device database.
We can’t guarantee that this service will always be available or reliable. Its handy for using with testing, but in production sites we would recommend installing WURFL on your own server.
is it using javascript?what about using php?
I wrote a script called isMobile in PHP which is a lot less code and does the job of detecting a mobile device (for any reason: redirection, mobile only scripts, etc)
Let me know what you think: http://www.justindocanto.com/scripts/detect-a-user-on-a-mobile-browser-or-device