Wednesday, December 19, 2007

Installing and Using WURFL with PHP

To build a download site that compatible for most mobile device is a very challenging task where we need to gather all these device capabilities and match it to our available services. But every device manufacturer might have a different format for describing its device capabilities.

WURFL is a very original idea to combine all device into a standard format that can be contribute by anyone. Using single XML file as it database core, most wireless handset capabilities can be query to it. By the time I post this, there's new version, WURFLDB that using real database. But I still prefer WURFL. WURFL with PHP is one of the great combination, where PHP is the most popluar language for developing a web/wap site, WURFL can deliver a query just in a blink of eye.

To download WURFL for PHP simply go to http://wurfl.sourceforge.net/php/index.php . Select the latest stable version. Once downloaded, simply unpack it into a web accessible folder (if you plan to make this detection available for public) or just put it into a internal folder and using command line PHP to access it.

Edit the wurfl_config.php file if necessary. In my installation, I edit the DATADIR directive to "/opt/www/html/wurfl/data/" instead of relative path "../data/". Make sure set permission on the folder to public writeable. For linux user, I recommend "chmod
/opt/www/html/wurfl/data/ 666". For Windows user (with folder security and permission set on, right click -> Properties -> Security). For initial folder content, download the WURFL database file wurfl.xml and save into the data dir.

Once saved, you can test the installation by accessing check_wurfl.php with full URL. There's text box for you to input the user agent manually. But on the real working environment, you maybe need to pass user's UA string from http header value $_SERVER['HTTP_USER_AGENT'] to the application. In my case, you can use PHP CURL function on wap site side and return the user agent using var_export($wurflObj->capabilities). You can also convert the result using any array to xml converter to switch the result's format. My sample installation is available here.

Once you get the data, it's now all up to you how to provide the appropriate service based on these data. Happy wurfl-ing !!

1 comment:

pretsh said...

very helpful article thanks.