Created
June 15, 2012 22:47
-
-
Save mattlundstrom/2939083 to your computer and use it in GitHub Desktop.
PHP Mobile Redirect
This file contains 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
<html> | |
<head> | |
<script type="text/javascript"> | |
function redirect(url) | |
{ | |
window.location.href = url; | |
} | |
</script> | |
</script> | |
</head> | |
<body> | |
<?php | |
$browser = $_SERVER['HTTP_USER_AGENT']; | |
$mobilesite = 'mobile.html'; // SITE TO FORWARD TO | |
$normalsite = 'normal.html'; // SITE TO FORWARD TO | |
$isMobile = false; | |
// IF ANY OF THESE STRINGS ARE FOUND IN USER AGENT | |
$agentslist = array( | |
'"iPhone"', | |
'"Blackberry"', | |
'"Opera Mini"', | |
'"Mobile Safari"', // ANDROID NEXUS ONE | |
'"webOS"', // PALM PRE | |
'"Palm"' // OLDER PALM | |
); | |
$count = count($agentslist); | |
for ($i = 0; $i < $count; $i++) | |
{ | |
if (preg_match($agentslist[$i], $browser)) | |
{ | |
$isMobile = true; | |
} | |
} | |
if ($isMobile == true) | |
{ | |
// IF MOBILE | |
echo '<script type="text/javascript">redirect("'. $mobilesite .'")</script>'; | |
} | |
else | |
{ | |
// IF NOT MOBILE | |
echo '<script type="text/javascript">redirect("'. $normalsite .'")</script>'; | |
} | |
?> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment