⌨ī¸Library

Learn how to use Mobile Detect library.

  1. Include composer's autoloader.

In case you are already using a PHP app, this step is probably already covered.

require __DIR__ . '/vendor/autoload.php';
  1. Instantiate the class.

use Detection\MobileDetect;
$detect = new MobileDetect();
  1. (Optional) Set the User-Agent.

Omit this step if your HTTP headers are available in $_SERVER global variable.

$detect->setUserAgent('Mozilla/5.0 (iPad; CPU OS 14_7 like Mac OS X) ...');
  1. Check for "mobile".

$isMobile = $detect->isMobile();
$isTablet = $detect->isTablet()

Last updated