Skip to content

Instantly share code, notes, and snippets.

@melloc01
Created August 28, 2014 15:22
Show Gist options
  • Save melloc01/34f3309a0b0d08e6171b to your computer and use it in GitHub Desktop.
Save melloc01/34f3309a0b0d08e6171b to your computer and use it in GitHub Desktop.
PHP - Check mobile devices by HTTP_USER_AGENT
$android = strpos(strtolower($_SERVER['HTTP_USER_AGENT']),"android");
$ipad = strpos(strtolower($_SERVER['HTTP_USER_AGENT']),"ipad");
$iphone = strpos(strtolower($_SERVER['HTTP_USER_AGENT']),"iphone");
$ipod = strpos(strtolower($_SERVER['HTTP_USER_AGENT']),"ipod");
if ( ($android === false) && ($ipad === false) && ($iphone === false) && ($ipod === false) )
$mobile = "false";
else
$mobile = "true";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment