Possible Duplicate:
Redirecting to a new page when a user is using Internet Explorer
I'm working on a version of my website which renders properly in Internet Explorer; what would a PHP script, which automatically redirects users with an IE user agent to (for example) /index-ie.php, look like?
Try
PHP have function $_SERVER['HTTP_USER_AGENT'] used to identify browser
if(using_ie())
{
//redirect
}
function using_ie()
{
$u_agent = $_SERVER['HTTP_USER_AGENT'];
$ub = False;
if(preg_match('/MSIE/i',$u_agent))
{
$ub = True;
}
return $ub;
}
you can use strpos
function to search the string for MSIE
. ex,
if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false) {
header('Location: /index-ie.php');
exit;
}
Get all information about user browser --
<?php
echo $_SERVER['HTTP_USER_AGENT'] . "\n\n";
$browser = get_browser(null, true);
print_r($browser);
?>
Try this :
function using_ie()
{
$u_agent = $_SERVER['HTTP_USER_AGENT'];
$ub = False;
if(preg_match('/MSIE/i',$u_agent))
{
$ub = True;
}
return $ub;
}
You will get value 1 if it is internet explorer.
Hope this works:
$user_agent = $_SERVER['HTTP_USER_AGENT'];
if(preg_match('MSIE',$user_agent))
{
header('Location: https://'. $_SERVER['HTTP_HOST'] .'/index.php']);
}