Device Detection

Presentation

Here is the presentation on device detection that I gave to Nick Bilton's "1 2 10" class at NYU IPT:

Device Detection Presentation [pdf]

Detection Examples

Simple Mobile Detection


Here is a simple example using a PHP library to detect if a browser (user-agent) is mobile or not:

  1. Download this PHP library and install it on your web server.
  2. Add the following PHP script to your server (in the same directory as the PHP library) and test with a web and mobile browser:
<?php

include("mobile_device_detect.php");

if (mobile_device_detect()) {
        print "im a mobile device";
} else {
        print "nope - im not a mobile device";
}

?>

Mobile Detection with WURFL


Here is an example using the WURFL Device Database to detect mobile devices and print out the device capabilities:

  1. Download the PHP WURFL library and install on your web server. Here is the latest version of the library.
  2. Download the WURFL device database and unzip/install on your web server: wurfl.zip.
  3. After you unzip wurlf.zip, move the file wurfl.xml in to a directory that is not under your web room (for this example it's fine) and make sure it's "write-able" by the web server. e.g.:
    mkdir data/
    mv wurfl.xml data/
    chmod 777 data/
    			
  4. Edit the file wurfl_config.php and make sure the DATADIR is pointing to the directory where you're storing wurfl.xml. Look for this line in the file:
    define("DATADIR", './data/');
    
  5. Add the following PHP script to your server (in the same directory as the PHP library) and test with a web and mobile browser:
<?php

require_once('./wurfl_config.php');
require_once(WURFL_CLASS_FILE);

// creating the WURFL object
$device = new wurfl_class($wurfl, $wurfl_agents);
$device->GetDeviceCapabilitiesFromAgent($_SERVER["HTTP_USER_AGENT"]);

if ($device->browser_is_wap ) {
        print "yep - is a mobile device";

        // print out device info
	print "<pre>";
        print_r($device->capabilities);
	print "</pre>";

} else {
        print "nope - is not a mobile device";
}

?>


	

Links + Tools

Firefox User-Agent Swicher

Simple PHP Mobile Detection

WURFL - Device Database

Tera-WURFL - a WURFL-based device detection library

Device Atlas - Another device detection service/library

Michael - myoung [at] 81nassau.com