Skip to content

Instantly share code, notes, and snippets.

@joshuabaker
Created December 6, 2010 17:12
Show Gist options
  • Save joshuabaker/730585 to your computer and use it in GitHub Desktop.
Save joshuabaker/730585 to your computer and use it in GitHub Desktop.
Detects whether a visitor is using a mobile device. This, although short, caters for all of the mobile device user agents listed on Wikipedia. Please first consider WURFL before using this in production.
function is_mobile()
{
return preg_match('/(ACER\ E101|Android|BlackBerry7230|BlackBerry7730|Blazer|LG\/U8120|LG\/U8130|LG\/U8138|LG\/U8180|LG\/U880|MIDP-2\.|Maemo\ Browser|MobilePhone|NetFront|Obigo|ObigoInternetBrowser|Opera\ Mini|SAMSUNG-SGH-i900|SymbianOS|UP\.Browser|WAP|Windows\ CE\;\ IEMobile|Windows\ CE\;\ PPC|Windows\ Phone|acer_S200|iPhone|iPod|webOS)/i', $_SERVER['HTTP_USER_AGENT']);
}
(ACER\ E101|Android|BlackBerry7230|BlackBerry7730|Blazer|LG\/U8120|LG\/U8130|LG\/U8138|LG\/U8180|LG\/U880|MIDP-2\.|Maemo\ Browser|MobilePhone|NetFront|Obigo|ObigoInternetBrowser|Opera\ Mini|SAMSUNG-SGH-i900|SymbianOS|UP\.Browser|WAP|Windows\ CE\;\ IEMobile|Windows\ CE\;\ PPC|Windows\ Phone|acer_S200|iPhone|iPod|webOS)
@joshuabaker
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment