These Days Tera-WURFL Webservice

Welcome to the These Days implementation of Tera-WURFL — a remote service for identifying the devices used by visitors to your website.

What is it for?

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.

How does it work?

How do I use it?

Feel free to use the These Days Tera-WURFL Webservice, but you can also easily install Tera-WURFL on your own server.

  1. Download the example.zip (4KB).
  2. Include TeraWurflRemoteClient.php in your PHP script.
    require_once ('TeraWurflRemoteClient.php');
  3. Instantiate a new TeraWurflRemoteClient object.
    $wurflObj = new TeraWurflRemoteClient('http://wurfl.thesedays.com/webservice.php');
  4. Define which capabilities you want to test for, i.e. 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");
  5. Define the response format (XML or JSON).
    $data_format = TeraWurflRemoteClient::$FORMAT_JSON;
  6. Call the remote service (the first parameter is the User Agent - leave it as null to let TeraWurflRemoteClient find the user agent from the server global variable).
    $wurflObj->getCapabilitiesFromAgent(null, $capabilities, $data_format);
  7. Use the results to serve the appropriate interface. This part will vary for each project, depending on the device capabilities you are targeting.
    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.