Small PHP code snippet to make a quick detect if the browser that requests your page is on a mobile device.
function isMobile(){ $device = ''; if( stristr($_SERVER['HTTP_USER_AGENT'],'ipad') ) { $device = "ipad"; } else if( stristr($_SERVER['HTTP_USER_AGENT'],'iphone') ) { $device = "iphone"; } else if( stristr($_SERVER['HTTP_USER_AGENT'],'blackberry') ) { $device = "blackberry"; } else if( stristr($_SERVER['HTTP_USER_AGENT'],'android') ) { $device = "android"; } if( $device ) { return $device; } return false; }
If it’s a mobile device (that is to say an iphone, an ipad, an android or a blackberry) returns the $device
variable. Else it returns false.