Tech, Gaming and Food Enthusiast
Detecting Mobile devices with WURFL and PHP
The Wireless Universal Resource File (WURFL) is an open source device library which describes itself as follows:
The WURFL is an “ambitious” configuration file that contains info about all known Wireless devices on earth. Of course, new devices are created and released at all times. While this configuration file is bound to be out of date one day after each update, chances are that the WURFL lists all of the WAP devices you can purchase in the nearest shops.
This configuration can be combined with their shiny new PHP and Java API’s to interrogate the user’s UAProf or USERAGENT strings to pin point the type of device the user is browsing on.
So how do we use it. The first step is to set the WURFL config file (wurfl-config.xml) which may look something like this.
Then to use the API, for this example I will be using the PHP API.
<?php
require_once 'WURFL_installation_root/WURFL/WURFLManagerProvider.php';
$wConf = 'Relative path to wurfl-config.xml';
$wManager = WURFL_WURFL_ManagerProvider::getWURFLManager($wConf);
$info = $wManager->getDeviceForHttpRequest($_SERVER);
?>
This code will load a large object of UAProf information which can be interrogated using the WURFL API functions (See Documentation).
It is so simple but very powerful and accurate, I would highly suggest giving it a try:
| Print article | This entry was posted by Matt on August 23, 2010 at 7:33 am, and is filed under Web Dev. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |