PHP mobile detect

The lightweight PHP class for detecting mobile devices.

Mobile_Detect is a lightweight PHP class for detecting mobile devices.It uses the user-agent string combined with specific HTTP headers todetect the mobile environment.

https://github.com/serbanghita/Mobile-Detect

DEMO - http://demo.mobiledetect.net/

http://code.google.com/p/php-mobile-detect/

Usage

Include and instantiate the class:

include Mobile_Detect.php;$detect = new Mobile_Detect();

Basic usage, looking for mobile devices or tablets:

if ($detect->isMobile()) { /* Any mobile device. */}if($detect->isTablet()){ /* Any tablet device. */}

Check for a specific platform with the help of the magic methods:

if($detect->isiOS()){ /* Code to run for the Apple's iOS platform. */}if($detect->isAndroidOS()){ /* Code to run for the Google's Android platform. */}

Other case insensitive available methods are isIphone(), isIpad(), isBlackBerry(), isKindle(), isOpera(), etc. For the full list of available methods check the demo.php file.

Alternative method is() for checking specific properties (in beta):

$detect->is(Chrome)$detect->is(iOS)$detect->is('UC Browser')[...]

Batch mode using setUserAgent():

$userAgents = array('Mozilla/5.0 (Linux; Android 4.0.4; Desire HD Build/IMM76D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19','BlackBerry7100i/4.1.0 Profile/MIDP-2.0 Configuration/CLDC-1.1 VendorID/103',[...]);foreach($userAgents as $userAgent){ $detect->setUserAgent($userAgent); $isMobile = $detect->isMobile(); $isTablet = $detect->isTablet(); /* Use the force however you want.*/}

Get the version() of components (in beta):

$detect->version(iPad); /* 4.3 (float) */$detect->version(iPhone) /* 3.1 (float) */$detect->version(Android); /* 2.1 (float) */$detect->version('Opera Mini'); /* 5.0 (float) */[...]