
Originally Posted by
deezy128
<?php
$iphone = strpos($_SERVER['HTTP_USER_AGENT'],"iPhone");
$android = strpos($_SERVER['HTTP_USER_AGENT'],"Android");
$palmpre = strpos($_SERVER['HTTP_USER_AGENT'],"webOS");
$berry = strpos($_SERVER['HTTP_USER_AGENT'],"BlackBerry");
$ipod = strpos($_SERVER['HTTP_USER_AGENT'],"iPod");
if ($iphone || $android || $palmpre || $ipod || $berry == true)
{
header('Location:
http://mobile.site.com/');
//OR
echo "<script>window.location='http://mobile.site.com'</script>";
}
else
{
header('Location:
http://regular.site.com/');
//OR
echo "<script>window.location='http://regular.site.com'</script>";
}
?>
Your script is bad and you should feel bad.
Code:
<?php
$agent = $_SERVER['HTTP_USER_AGENT'];
$mobileUseragents = array(
'iPhone',
'Palm',
'BlackBerry',
'Opera Mini',
'Android',
'Windows CE',
'HTC',
'IEMobile',
'Phone',
'Kindle',
'UP.Browser',
'MIDP',
'Symbian',
'iPod',
'webOS'
);
global $mobileUseragents;
foreach($mobileUseragents as $mobileUseragent){
if(stripos($agent, $mobileUseragent) !== FALSE){
$mobile=1;
}
}
if($mobile) {
header("Location: http://mobile-version.com");
} else {
header("Location: http://web-version.com");
}
?>
Bookmarks