Welcome to the These Days implementation of Tera-WURFL — a remote service for identifying the devices used by visitors to your website.
Some websites have different interfaces for desktop, touch mobile, non-touch mobile, iPad, etc. Tera-WURFL is a tool for detecting the capabilities of devices so you know which version of your website to serve to each visitor. It is not feasible to write a device detection script for every project, because there are already thousands of User Agent strings in use and new devices are being released all the time. A much easier solution is to call the Tera-WURFL webservice remotely.
Feel free to use the These Days Tera-WURFL Webservice, but you can also easily install Tera-WURFL on your own server.
require_once ('TeraWurflRemoteClient.php');
$wurflObj = new TeraWurflRemoteClient('http://wurfl.thesedays.com/webservice.php');
is_wireless_device, pointing_method, device_os. For a general overview of the most important capabilities, use product_info (full list here).$capabilities = array("product_info");
$data_format = TeraWurflRemoteClient::$FORMAT_JSON;
$wurflObj->getCapabilitiesFromAgent(null, $capabilities, $data_format);
if ($wurflObj->getDeviceCapability("is_tablet")) {
$result = "Show iPad website";
} elseif ($wurflObj->getDeviceCapability("is_wireless_device")) {
$result = "Show mobile website";
} else {
$result = "Show normal website";
}
Don't forget to give your users a way of overriding automatic device detection. Even Tera-WURFL can get it wrong sometimes, and anyway some users prefer to view full sites on their mobile phones. The user is king!
The full source code from this example is available in the example.zip (4KB) download.