Created
March 25, 2012 10:20
-
-
Save scarvell/2192706 to your computer and use it in GitHub Desktop.
Detects if visitor is using a mobile device
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function isMobileBrowser() | |
{ | |
$user_agent = $_SERVER['HTTP_USER_AGENT']; | |
$mobileBrowser = false; | |
// iPhone check | |
if( eregi('ipod',$user_agent)|| eregi('iphone',$user_agent) ) | |
{ | |
$mobileBrowser = true; | |
} | |
// Black Berry check | |
if( eregi('blackberry',$user_agent) ) | |
{ | |
$mobileBrowser = true; | |
} | |
// End Opera check | |
if( eregi('opera mini',$user_agent) ) | |
{ | |
$mobileBrowser = true; | |
} | |
// Android check | |
if( eregi('android',$user_agent) ) | |
{ | |
$mobileBrowser = true; | |
} | |
// Palm check | |
if( preg_match('/(palm os|hiptop|avantgo|blazer|xiino|plucker|palm|elaine)/i', $user_agent) ) | |
{ | |
$mobileBrowser = true; | |
} | |
// Windows phone check | |
if( preg_match('/(windows ce; ppc;|windows ce; smartphone;|windows ce; iemobile)/i', $user_agent) ) | |
{ | |
$mobileBrowser = true; | |
} | |
return $mobileBrowser; | |
} | |
echo ( isMobileBrowser() ) ? 'Mobile user' : 'desktop user'; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment