explaingit

serbanghita/mobile-detect

10,682PHPAudience · developerComplexity · 2/5LicenseSetup · easy

TLDR

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.

Mindmap

mindmap
  root((mobile-detect))
    What it does
      Detect phone vs tablet
      Read User-Agent
      HTTP header parsing
    Versions
      v4 current PHP 8.2
      v3 LTS PHP 7.4
      v2 deprecated
    Use cases
      Redirect mobile users
      Skip heavy assets
      Adjust features
    Resources
      Gitbook docs
      Live demo site
      MIT license
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Redirect mobile visitors to a mobile-optimized layout or skip loading heavy assets on small screens.

USE CASE 2

Detect tablets separately from phones in a PHP app to apply different UI treatments for each device type.

USE CASE 3

Drop the library into a legacy PHP 7.4 environment using the long-term support v3 branch.

Tech stack

PHP

Getting it running

Difficulty · easy Time to first run · 5min

Version 4 requires PHP 8.2 or higher, use v3 for PHP 7.4 environments.

MIT license, use freely for any purpose, including commercial use, as long as you keep the copyright notice.

In plain English

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.

Copy-paste prompts

Prompt 1
Using mobile-detect v4 in PHP 8.2, show me how to detect if the current visitor is on a mobile phone and redirect them to /mobile.
Prompt 2
How do I install mobile-detect and check in PHP whether a visitor is on a tablet versus a phone?
Prompt 3
I'm on PHP 7.4 and need device detection, which version of mobile-detect should I use and how do I install it?
Open on GitHub → Explain another repo

← serbanghita on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.