TheseDays.com: An Easy Way to Detect Mobile Devices
Note: This article was originally published at PHPDeveloper on 11 August 2010.
WURFL, The Wireless Universal Resource File (WURFL) is an open source project which collects information about all of the different mobile devices in use. It is constantly being updated, so as long as you keep your WURFL definitions up-to-date you don't have to worry about your detection scripts not recognising new devices. By querying a WURFL database with your visitor's User Agent string, you can not only determine whether the device they are using is a mobile device, but whether it has a touch screen, can make phone calls, is a tablet (iPad) and more.
They include a snippet of code that uses the Tera-WURFL service and a call to getCapabilitiesFromAgent to see what kind of client is making the requests and what it supports.