Hey everyone. Had a quick question hopefully someone here can help me out with. I'm trying to figure out how to get a link to redirect users depending on their broswer. (The offer I'm working with doesn't work with Internet Explorer 8). Basically I want all IE8 traffic to go to one page, and all other traffic to another. I've been looking around and here's the best I've found so far: <? //if its MSIE then if ($name = strstr ($HTTP_USER_AGENT, "MSIE")) { //go to Index.php Header ("Location: index.php"); } else { //else go to BrowserUpdate Header ("Location: browser_options.php"); } ?> What would I have to change to get it to isolate IE8 as I don't want to redirect any more users than I absolutely have to, and also, will the above script work. Thanks in advance for any help
That looks like a PHP code. It should be something like this: <?php if (preg_match("/MSIE 8/", $_SERVER['HTTP_USER_AGENT'])) header("Location: index.php"); else header("Location: browser_options.php"); ?> PHP:
Since this is in the javascript section I'll add you an alternative.. <script langauge="javascript"> function checkIE() { var ua = window.navigator.userAgent var ie = ua.indexOf ("MSIE ") if (ie >= 8) window.location = "http://www.example.com"; else return 0 } </script> <body onload="checkIE();"> Code (markup):
Thanks to both of you for the help. I really appreciate it. As a bit of a follow up is there any advantage to using PHP or Javascript to do this or does it not really matter?
Far better to avoid JavaScript unless necessary, as it is possible that the user does not have it enabled (only a very small percentage). You are probably better off inserting your code into 'index.php', doing nothing if the browser is I.E, and redirecting if it isn't. This will mean that only users that aren't using MSIE will then be redirected. I don't use php but probably something like: <?php if (preg_match("/MSIE /", $_SERVER['HTTP_USER_AGENT']) == 0) header("Location: browser_options.php"); ?> ... Your msie index.php would go here ... Code (markup): Why is it that you need a different website for each browser? Cross browser development is a pain, but can be done if taken the time.
Thanks. I'll take your advice and go with PHP on this one. The issue for me is it's not my site that's causing the problem. It's an affiliate offer, and sadly, their website sets off all sorts of security and browser alerts in IE8, which basically kills it since the website in question is an online shopping cart. I'll be finding a better solution in the long run but in the short term redirecting IE8 to a similar but slightly poorer site is my best way of dealing with it