Last active
August 29, 2015 14:24
-
-
Save Zillionx/5253ba4121b9d5c8b3b5 to your computer and use it in GitHub Desktop.
PHP OS mobile detection with url redirect
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
/* 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