Detect Device using php code

Posted: May 24, 2012 in php
Tags: , , ,

Here we can detect the mobile devices using php code. actually the code is detecting the device usign user agent.

please click here to download mobile detect code .

Usage:

1. Download mobile detect code from above link.

2.Include and instantiate the class

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

3.Check for a specific platform:

if($detect->isiOS()){
    // code to run for the Apple iOS platform.
}
if($detect->isAndroidOS()){
    // code to run for the Google 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 or the wiki.

Alternatively, if you are only interested in checking to see if the user is using a mobile device, without caring for specific platform:

if ($detect->isMobile()) {
    // any mobile platform
}
if($detect->isTablet()){
    // any tablet
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s