Mobile Detect
Lightweight PHP class for detecting mobile phones and tablets from the User-Agent.
Repository Health
Technical Analysis
Mobile Detect is a widely used, lightweight PHP class for server-side detection of mobile devices, including tablets. It inspects the incoming User-Agent string together with specific HTTP headers to determine whether a request comes from a phone, a tablet, or a particular vendor, operating system, or browser.
With thousands of matching rules covering vendors, models, and platforms, it lets PHP applications tailor content, switch templates, trigger mobile redirects, or gate features based on device class — all before a single line of client-side JavaScript runs. It has no heavyweight dependencies beyond a PSR-16 cache interface and is a long-standing staple of the PHP ecosystem.
What You Get
- isMobile() and isTablet() checks for quick device-class branching
- Hundreds of vendor, model, OS, and browser detection rules
- Dynamic magic-method checks like isIOS() or isAndroidOS()
- PSR-16 (SimpleCache) support to cache detection results
- A standalone build option for use without Composer autoloading
Common Use Cases
- Serving a mobile-optimized template or layout server-side
- Redirecting phone visitors to a dedicated mobile site or AMP page
- Toggling features or ad slots based on device class
- Collecting device analytics from the User-Agent on the server
Under The Hood
Architecture - The library lives under src/ in the Detection\ namespace (PSR-4), centered on a MobileDetect class that loads large rule dictionaries (device vendors, operating systems, browsers, and utility regexes) and matches them against the User-Agent and HTTP headers. Detection results can be memoized through an injected PSR-16 cache, and magic __call handling turns rule names into isX() methods.
Tech Stack - Modern PHP (>=8.2) with a single runtime dependency on psr/simple-cache. Development uses PHPUnit, PHPStan, php-cs-fixer, and phpbench for benchmarking, with a Docker Compose setup for testing across environments.
Code Quality - The 4.x line is a substantial modernization with strict typing, PHPStan static analysis, an extensive tests/ suite, and dedicated performance benchmarking (PERFORMANCE.md, phpbench). Rule data is kept in structured JSON, keeping detection logic separate from the matching engine.
API Design - The API is approachable: instantiate MobileDetect, optionally set the User-Agent, then call isMobile()/isTablet() or vendor-specific helpers. The magic-method pattern keeps the surface small while supporting a huge matrix of checks, and PSR-16 caching integrates cleanly for high-traffic sites.
Used by 2 apps in this directory
Passbolt API
Password Manager · Security
Self-hosted, end-to-end encrypted password manager API built for teams who demand full ownership of their credentials.
solidtime
Productivity · Invoicing Finance
Modern open-source time tracker for freelancers and agencies with invoicing, multi-org support, and Toggl/Clockify migration built in.