MobileDetect PHP
Github4.8.x3.74.x2.8.xDemo
  • Introduction
  • Install
  • How to use (composer)
  • How to use (standalone)
  • The constructor
  • Example
  • Other versions
  • Demo
  • Performance
  • Contribute
  • Developing code
  • Project structure
  • Extending / Porting
  • Add new module, plugin or port
  • Plugins, Modules and Ports
  • Credits
Powered by GitBook
On this page

Was this helpful?

Edit on GitHub

How to use (composer)

Learn how to use Mobile Detect library via composer

composer require mobiledetect/mobiledetectlib
// composer.json
{
    "require": {
        "mobiledetect/mobiledetectlib": "4.8.09" // Change to the lastest version.
    }
}
// your_script.php
// (optional) You're app is probably already using composer autoloader.
require __DIR__ . '/vendor/autoload.php';

// (mandatory)
use Detection\MobileDetect;
$detect = new MobileDetect();

// (optional) By default the Mobile Detect library auto-detects the HTTP headers from $_SERVER global variable.
$detect->setUserAgent('Mozilla/5.0 (iPad; CPU OS 14_7 like Mac OS X) ...');

// Use whatever methods you want.
$isMobile = $detect->isMobile();
$isTablet = $detect->isTablet();

var_dump($isMobile);
var_dump($isTablet);

var_dump($detect); // debug
PreviousInstallNextHow to use (standalone)

Last updated 4 months ago

Was this helpful?