Skip to content

Instantly share code, notes, and snippets.

@jaredatch
Created August 17, 2012 07:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaredatch/3376641 to your computer and use it in GitHub Desktop.
Save jaredatch/3376641 to your computer and use it in GitHub Desktop.
try to detect if is mobile
<?php
/**
* Check useragent string for mobile device
*
* @return boolean if mobile device is detected
*/
function ja_is_mobile() {
$useragent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : "";
if ( preg_match( '/(alcatel|amoi|android|avantgo|blackberry|benq|cell|cricket|docomo|elaine|htc|iemobile|iphone|ipad|ipaq|ipod|j2me|java|lg|midp|mini|mmp|mobi|motorola|nec-|nokia|palm|panasonic|philips|phone|sagem|sharp|sie-|smartphone|sony|symbian|t-mobile|telus|up\.browser|up\.link|vodafone|wap|wm5|webos|wireless|xda|xoom|zte)/i', $useragent ) ) {
return true;
} else {
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment