January 2012
Intermediate to advanced
178 pages
4h 31m
English
Now, in your web directory (such as Sites or public_html), create the following PHP file (name it something like wurfl-test.php). The first time you visit it from your Android device (or any other browser), it will take a long time as it builds the initial cache. After that, it should be zippy. Figure A-1 shows how this should appear in your browser. You can now modify this PHP code to suit your needs:
<html>
<head>
<meta name="viewport" content="user-scalable=no, width=device-width" />
<title>WURFL Test</title>
<?php
define("WURFL_DIR", "/Users/NAME/src/wurfl-php-1.3.1/WURFL/");
define("RESOURCES_DIR", "/Users/NAME/src/wurfl-php-1.3.1/");
require_once WURFL_DIR . 'Application.php';
$wurflConfigFile = RESOURCES_DIR . 'wurfl-config.xml';
$wurflConfig = new WURFL_Configuration_XmlConfig($wurflConfigFile);
$wurflManagerFactory = new WURFL_WURFLManagerFactory($wurflConfig);
$wurflManager = $wurflManagerFactory->create();
$wurflInfo = $wurflManager->getWURFLInfo();
$requestingDevice = $wurflManager->getDeviceForHttpRequest($_SERVER);
$is_android = FALSE;
if ($requestingDevice->getCapability("device_os") == "Android") {
$is_android = TRUE;
}
?>
</head>
<body>
<?php
if ($is_android) {
echo "I spy an Android phone.";
}
?>
<ul>
<?php
foreach ($requestingDevice->getAllCapabilities() as $key => $value) {
echo "<li>$key = $value";
}
?>
</ul>
</body>
</html>I couldn’t use ~, so I had to put in the full path to the
WURFL stuff; replace
/Users/NAME/src/wurfl-php-1.3.1/ with ...
Read now
Unlock full access