Skip to content

Instantly share code, notes, and snippets.

@Zillionx
Last active August 29, 2015 14:24
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 Zillionx/5253ba4121b9d5c8b3b5 to your computer and use it in GitHub Desktop.
Save Zillionx/5253ba4121b9d5c8b3b5 to your computer and use it in GitHub Desktop.
PHP OS mobile detection with url redirect
/* Zilli 201102
To detect the OS mobile system on the client device,
match the value of $_SERVER[‘HTTP_USER_AGENT’],
then redirect to mobile url with the header php function.
*/
<?PHP
function mobileDevice()
{
$type = $_SERVER[‘HTTP_USER_AGENT’];
if(strpos((string)$type, “Windows Phone”) != false || strpos((string)$type, “iPhone”) != false || strpos((string)$type, “Android”) != false)
return true;
else
return false;
}
if(mobileDevice() == true)
header(‘Location: http://index-mobile.html‘);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment