I am using the code below in order to redirect the users who use Internet Explorer to a new page, but obviously there is something wrong with the code, since the site doesn't load anymore when I 开发者_开发问答am using Internet Explorer.
Here is the code:
<?php
if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== FALSE) {
$url = htmlspecialchars($_GET['url']);
header( 'Location: http://'.$url.'' ) ;
}
?>
Since I don't know what I am doing wrong it would be greatly appreciated if someone could post the right way to do it with the right coding.
Thanks in advance.
You can use get_browser() to get the user browser and then use the if condition.
You can try this:
$browser = get_browser(null, true);
if($browser['browser'] == "Internet Explorer"){
$url = htmlspecialchars($_GET['url']);
header( 'Location: http://'.$url.'' );
} else {
// do something...
}
strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== FALSE)
!== typo ? It should be something like
strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') == TRUE)
For modern IE you can use:
if (strpos($_SERVER['HTTP_USER_AGENT'], 'Trident') !== false) {
header('Location: ie-page.php');
exit;
} else {
print "Hello World";
}
精彩评论