Mobile detect with PHP | wdrfree post

Mobile detect with PHP

Tuesday 10th, Nov, 2015 | #PHP #Mobile

View More Demo Download

Today it is essential to detect whether a user is visiting a page from a cell phone mobile or a desktop PC to give you a better browsing experience

A simple way is use $_SERVER["HTTP_USER_AGENT"] php variable

Simple example detect mobile device php code

function isMobile() {
    return preg_match("/(android|avantgo|blackberry|bolt|boost|cricket|docomo|fone|hiptop|mini|mobi|palm|phone|pie|tablet|up\.browser|up\.link|webos|wos)/i", $_SERVER["HTTP_USER_AGENT"]);

}else {

Other way is use Mobile Detect

Mobile Detect is a lightweight PHP class for detecting mobile devices (including tablets). It uses the User-Agent string combined with specific HTTP headers to detect the mobile environment.

How to use Mobile detect PHP?

// Include and instantiate the class.
require_once 'Mobile_Detect.php';
$detect = new Mobile_Detect;
// Any mobile device (phones or tablets).
if ( $detect->isMobile() ) {
// Any tablet device.
if( $detect->isTablet() ){
// Exclude tablets.
if( $detect->isMobile() && !$detect->isTablet() ){
// Check for a specific platform with the help of the magic methods:
if( $detect->isiOS() ){
if( $detect->isAndroidOS() ){