Skip to content

Instantly share code, notes, and snippets.

@serverok
Created September 8, 2024 07:03
Show Gist options
  • Save serverok/03d39aa0fcdabb24ac4df0e8006a7477 to your computer and use it in GitHub Desktop.
Save serverok/03d39aa0fcdabb24ac4df0e8006a7477 to your computer and use it in GitHub Desktop.
PHP function to identify Mobile Users
function is_mobile()
{
if (empty($_SERVER["HTTP_USER_AGENT"])) {
return false;
}
return @preg_match("/(android|webos|avantgo|iphone|ipad|ipod|blackberry|iemobile|bolt|boost|cricket|docomo|fone|hiptop|mini|opera mini|kitkat|mobi|palm|phone|pie|tablet|up\.browser|up\.link|webos|wos)/i", ''.$_SERVER["HTTP_USER_AGENT"]);
}
function is_iphone()
{
if (empty($_SERVER["HTTP_USER_AGENT"])) {
return false;
}
return @preg_match("/(iphone|ipod)/i", ''.$_SERVER["HTTP_USER_AGENT"]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment