im trying to redirect users to another page if they are using internet explorer but this code doen't redirect them it loads the page up as normal on i.e.
I have tried different variations of MSIE but nothing seems to work
session_start();
if (strpos($_SERVER['HTTP_USER_AGENT'], '/MSIE/i') !== false){
header('Location: /ie.php');
die();
}else{
echo "User Agent not recognised.";
}
any one have any ideas?
try this:
session_start();
if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false){
header('Location: /ie.php');
die();
}else{
echo "User Agent not recognised.";
}
The reason is that strpos
's second parameter, the needle, is not supposed to be a regular expression.
try to put ob_start(); in top of PHP file
Change '/MSIE/i'
to simply MSIE
and try it. Also, do you need the die() function?
There is another way in which you don't need php at all, and it's conditional comments:
<!--[if IE]>
<?php echo "User is using Internet Explorer"; ?>
<![endif]-->
<!--[if IE 6]>
<?php echo "User is using Internet Explorer 6"; ?>
<![endif]-->
etc...
Also you can get if the explorer is IE and if the version is lesser or greater than X:
Code if User uses IE and it's below version 9 Code if User uses IE and it's below than or equal to version 7 Code if User uses IE and it's greater than version 6
The advantages are that you can also pick the version of the browser, easy to implement, and you are using a little less resources from your server xD (although it would be a insignificant difference).
Another advantage is that you can use that to include css or js files in the header of your page depending on the browser.
The disadvantage is that you has less control as it's browser based(client side).