Skip to content

Instantly share code, notes, and snippets.

@benmay
Created May 21, 2013 11:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benmay/812149dee707828fdb73 to your computer and use it in GitHub Desktop.
Save benmay/812149dee707828fdb73 to your computer and use it in GitHub Desktop.
<?php
function mysite_is_mobile()
{
$isMobile = preg_match("#(ipod|iphone|android|opera mini|blackberry|pre/|palm os|palm|hiptop|avantgo|plucker|xiino|blazer|elaine|iris|3g_t|windows ce|opera mobi|windows ce; smartphone;|windows ce; iemobile)#i", $_SERVER['HTTP_USER_AGENT'] );
// If an IP is X then show mobile (good for debugging m site)
// if( $_SERVER['REMOTE_ADDR'] == 'xxx.xxx.xxx.xxx' )
// return true;
return $isMobile == 1 ? true : false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment