I'm new to PHP and I would like to redirect the visitors of my website based on their operating system. Below is my solution. Is there anything that needs to be optimized?
<?php
// MOBILE
$android = strpos($_SERVER['HTTP_USER_AGENT'],"Android");
$blackberry = strpos($_SERVER['HTTP_USER_AGENT'],"BB10");
$ios = strpos($_SERVER['HTTP_USER_AGENT'],"iOS");
// DESKTOP
$windows = strpos($_SERVER['HTTP_USER_AGENT'],"Windows");
$mac = strpos($_SERVER['HTTP_USER_AGENT'],"Mac");
// REDIRECTS
// MOBILE
if ($android == true)
{
header('Location: http://www.example.com/android');
}
else if ($blackberry == true)
{
header('Location: http://www.example.com/blackberry');
}
else if ($ios == true)
{
header('Location: http://www.example.com/ios');
}
// DESKTOP
else if ($windows == true)
{
header('Location: http://www.example.com/windows');
}
else if ($mac == true)
{
header('Location: http://www.example.com/mac');
}
?>
Thanks. Patrick