• 0

re-direct if IE detected


Question

Hi, I have a page on my site that i want to change so that if is accessed using IE, it will redirect the user to a page of my choosing. Could anyone provide me with the code for how to do this.

Link to comment
Share on other sites

14 answers to this question

Recommended Posts

  • 0

I've heard that it's not always reliable to check the user's browser from PHP, but I admit I haven't researched it much. You're probably fine doing it this way since the cases where it doesn't work is likely someone doing something they shouldn't be doing.

Link to comment
Share on other sites

  • 0
I've heard that it's not always reliable to check the user's browser from PHP, but I admit I haven't researched it much. You're probably fine doing it this way since the cases where it doesn't work is likely someone doing something they shouldn't be doing.

It's actually very unreliable. In fact, there's not a single way you could discriminate between different browsers by relying solely on some variable supplied by a browser, because they could all be changed with relative ease. The only sure way is to put a hack together that exploits the varying degree of technological sophistication amongst the different rendering engines, and make them filter themselves (if the browser doesn't support a certain technology, editing the UA won't change a damn thing). Suffice it to say, not very pretty and often not possible anyways. Only under very limited circumstances could you effectively tell what browser is what, so there's basically no point in trying to discriminate amongst them. The effort would be much better spent making the website just work with every browser.

Link to comment
Share on other sites

  • 0

bad idea, just make it work in every browser :)

but if you really want to do this there is a better way

<!--[if lte IE 6]>

<script type="text/javascript">

window.location = "blabla";

</script>

<![endif]-->

will let you redirect ie6. I don't see any reason to redirect ie7 because a lot of the hacks aren't necessary anymore and making a site work in ff, opera and ie7 isn't really that difficult

Link to comment
Share on other sites

  • 0
bad idea, just make it work in every browser :)

but if you really want to do this there is a better way

<!--[if lte IE 6]>

<script type="text/javascript">

window.location = "blabla";

</script>

<![endif]-->

will let you redirect ie6. I don't see any reason to redirect ie7 because a lot of the hacks aren't necessary anymore and making a site work in ff, opera and ie7 isn't really that difficult

IE7 has some rather....shall we say, interesting, rendering bugs that I don't believe occured in IE6.

In any case, why not just use if lt IE7? (1 less character!), and the javascript redirect won't work for everyone. Same problem with meta redirects as well.

Link to comment
Share on other sites

  • 0
In fact, there's not a single way you could discriminate between different browsers by relying solely on some variable supplied by a browser, because they could all be changed with relative ease...

Only under very limited circumstances could you effectively tell what browser is what, so there's basically no point in trying to discriminate amongst them. The effort would be much better spent making the website just work with every browser.

Until Microsoft get their act together and properly deal with the XHTML1.1 content type (and by which time you shouldn't / won't want to redirect) you can check $_SERVER['HTTP_ACCEPT'] / Request.ServerVariables("HTTP_ACCEPT") for "application/xhtml+xml". Opera says it can handle it, as does the fox, Safari does the IE trick of allegedly supporting everything ("*/*"), unless that's changed recently. Whilst UA is easy peasy (even for IE) to change, the Accept shouldn't be able to be altered.

Link to comment
Share on other sites

  • 0
Until Microsoft get their act together and properly deal with the XHTML1.1 content type (and by which time you shouldn't / won't want to redirect) you can check $_SERVER['HTTP_ACCEPT'] / Request.ServerVariables("HTTP_ACCEPT") for "application/xhtml+xml". Opera says it can handle it, as does the fox, Safari does the IE trick of allegedly supporting everything ("*/*"), unless that's changed recently. Whilst UA is easy peasy (even for IE) to change, the Accept shouldn't be able to be altered.

it's possible, why anyone would ever want to change it is beyond me. but as you said, using http_accept will give you problems with safari (which is more correct than IE in claiming */*).

Link to comment
Share on other sites

  • 0

I used to check to see if it contained "MSIE", but didn't contain Opera (because Opera used to identify as IE)

And don't check for Safari, check for WebKit, otherwise you'll break other mac browsers (and some are really fun, they use WebKit but override XHTML rendering and treat it as RSS!)

:sleep:

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.