Use isMobile() function of MobileDetect class to check if the site is accessed from mobile devices.
Use isTablet() function to detect tablet device in PHP.
Use isiOS() and isAndroidOS() functions to check device operating system is iOS or Android.
// Include MobileDetect library
include_once 'MobileDetect.class.php';
// Create an instance of MobileDetect class
$mdetect = new MobileDetect();
if($mdetect->isMobile()){
// Detect mobile/tablet
if($mdetect->isTablet()){
echo 'Tablet Device Detected!
';
}else{
echo 'Mobile Device Detected!
';
}
// Detect platform
if($mdetect->isiOS()){
echo 'IOS';
}elseif($mdetect->isAndroidOS()){
echo 'ANDROID';
}
}else{
echo 'Desktop Detected!';
}
Use the following code sample to detect mobile devices and redirect the user to the mobile version of the website.
if($mdetect->isMobile()){
header("Location:https://m.codexworld.com");
exit;
}