Saturday, February 07, 2009

How to confuse IE with a 302 redirect

It’s very simple, create a PHP pages called test.php, the contents of which are

<?php
  header("Location: test.php");
  exit;
?>

Now point IE8 (probably earlier versions of IE as well I’d guess) at the page and watch as it tries in vain to fetch the page. It eventually times out, after trying to fetch the same page over 1000 times (take a look with Fiddler to see the problem). FireFox and Chrome are much more sensible in this scenario and give up quite soon. As the dumb developer who caused this problem, it took me quite some time to figure out my redirect wasn’t working rather than the website being very ill

2 comments:

Anonymous said...

I remember having a rather odd and similar problem with Alexa about a month ago, although that was more to do with Apache getting stuck in a redirect loop (I would have thought Alexa could have got that right...) infinite loops are very hard to locate, because they don't actually generate any errors.

Also, it's technically a 300 redirect. A 302 is a 'moved permanently' redirect.

Doogal said...

header("Location: test.php") in PHP causes a 302 redirect (see http://uk2.php.net/header), although I imagine a 300 would cause the same problem