Detect Mobile Devices Using PHP Class


Detect Mobile Devices Using PHP Class

   

How to detect mobile devices using PHP using Mobile Detect class, in this tutorial you will learn how to detect tables and mobile devices, Perhaps this is simplest way to detect a mobile device. Mobile Detect class uses the User-Agent string combined with specific HTTP headers to detect the mobile environment. so yo can redirect mobile users to your mobile site our do what you want to do with it. 
 
Download Demo  Demo link is not working please try again later.

First of all download "Detect Mobile PHP Class"  check usage below

How to use detect mobile PHP class 

Detecting mobile devices 
 

<?php 
//Include Mobile_detect.php class
require_once 'Mobile_Detect.php';
//instantiate the class
$detect = new Mobile_Detect;
 
// Any mobile device (phones).
$deviceType = ($detect->isMobile() ? 'computer' : 'phone');
if ( $detect->isMobile() ) {
  echo 'You are  using '. $deviceType;
}
?>
You can detect a specific platform

<?php 
//Include Mobile_detect.php class
require_once 'Mobile_Detect.php';
//instantiate the class
$detect = new Mobile_Detect;

//show version if Iphone
if( $detect->isiOS() ){
 $detect->version('iPhone');
}
 //show version if Android phone
if( $detect->isAndroidOS() ){
 $detect->version('Android'); 
}
?>

 

redirecting to mobile version of website 



<?php 
//Include Mobile_detect.php class
require_once 'Mobile_Detect.php';
//instantiate the class
$detect = new Mobile_Detect;
// Check any mobile device (phones or tablets) or computer.
$deviceType = ($detect->isMobile() ? ($detect->isTablet() ? 'tablet' : 'phone') : 'computer');
if($deviceType === 'phone'){
    header('Location: https://m.youtube.com/');
     }
?>

 

Check the custom detection methods From Here

 

Comments