What is the simplest way to tell if a user is using a mobile device to browse my site using PHP?
I have come across many classes that you can use but I was hoping fo
PHP device detection from 51Degrees.com does exactly what you want - detects mobile devices and various properties associated with detected devices. It is simple to use and requires no maintenance. Set up is done in 4 easy steps:
require_once 'path/to/core/51Degrees.php';
require_once 'path/to/core/51Degrees_usage.php';
if ($_51d['IsMobile'])
{
//Start coding for a mobile device here.
}
51Degrees device detector does not use regular expressions for detections. Only important parts of HTTP headers are used to match devices. Which makes this solution the fastest (5 000 000 detections per second on mediocre hardware) and most accurate (99.97% accuracy) as hundreds of new devices are added to the database weekly (Supported device types include consoles, smart TVs, e-readers, tablets and more).
Software is open source distributed under Mozilla Public License 2 and compatible with commercial and open source projects. As a bonus 51Degrees solution also contains a complementary PHP image optimiser that can automatically resize images for mobile devices.
By default 51Degrees PHP device detector uses Lite data file which is free and contains over 30000 devices and 50 properties for each device. Lite file is updated once every 3 month. If you want to have a higher level of details about requesting mobile devices, then Premium and Enterprise data files are available. Premium contains well over 70000 devices and 100 properties for each device with weekly updates. Enterprise is updated daily and contains over 150000 devices with 150 properties for each.
Full list of device properties.
Compare data files.