Skip to content

A varnish setup to cache wordpress website with mobile detection

Notifications You must be signed in to change notification settings

moayyadfaris/wordpress-varnish-mobile-detect

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 

Repository files navigation

wordpress-varnish-mobile-detect

A vcl to server wordpress website with mobile detection

use the following function in your php

function isMobileDevice(){
	if(isset($_SERVER['HTTP_X_VARNISH'])){
		if ($_SERVER['HTTP_X_DEVICE']=='MOBILE'){
			return true;
		}else{
			return false;
		}
	}else{
		$aMobileUA = array(
        '/iphone/i' => 'iPhone', 
        '/ipod/i' => 'iPod', 
        '/ipad/i' => 'iPad', 
        '/android/i' => 'Android', 
        '/blackberry/i' => 'BlackBerry', 
        '/webos/i' => 'Mobile'
    );

    //Return true if Mobile User Agent is detected
    foreach($aMobileUA as $sMobileKey => $sMobileOS){
        if(preg_match($sMobileKey, $_SERVER['HTTP_USER_AGENT'])){
            return true;
        }
    }
    //Otherwise return false..  
    return false;
	}

    
}

About

A varnish setup to cache wordpress website with mobile detection

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages