Mobile-Detect
Mobile_Detect is a lightweight PHP class for detecting mobile devices (including tablets). It uses the User-Agent string combined with specific HTTP headers to detect the mobile environment.
Mobile-Detect is a PHP library that tells your app whether the current visitor is on a mobile phone or tablet by reading browser headers, so you can serve different layouts or features per device.
Mobile-Detect is a PHP library that tells your web application whether the current visitor is using a mobile phone or tablet. It works by reading the User-Agent string, which is a short piece of text that every browser sends with each request to identify itself, and combining that with certain HTTP headers to figure out what kind of device is making the request.
The use case is straightforward: if you want your PHP application to behave differently for mobile visitors, such as redirecting them to a mobile layout, skipping heavy assets, or adjusting features, you include this library and call its detection methods. The library is small and focused entirely on device detection rather than being a general-purpose browser utility.
The library has three active version lines. Version 2 is deprecated and only supports older PHP releases. Version 3 is in long-term support mode for PHP 7.4 environments. Version 4 is the current recommended version and requires PHP 8.2 or higher. Each version lives on its own branch on GitHub. Users on modern PHP should use version 4.
Documentation is hosted on Gitbook, and there is a live demo site where you can point a mobile browser to see what the library detects about your device. The project is open source under the MIT license and maintained by the original author, who accepts donations to cover hosting and development time.
Where it fits
- Redirect mobile visitors to a mobile-optimized layout or skip loading heavy assets on small screens.
- Detect tablets separately from phones in a PHP app to apply different UI treatments for each device type.
- Drop the library into a legacy PHP 7.4 environment using the long-term support v3 branch.