When I uploaded a custom forum I wrote to our production server, the header("Location..") call would not work in Internet Explorer (IE) browsers (IE6,IE7,IE8). It worked in some cases, but never in cases when they were POST processing pages.
The issue was with header("Location: ...");
We are running an IIS6, PHP 5.2.9 server and for some reason when I tried using header("Location ..") on pages that processed a form (via POST), the header("Location ...") call would stop page execution and return a "Cannot display page error", it wasn't a 404 either.
After spending a good amount of time figuring out if it was just an error due a configuration issue on the production server, it turned out that all I had to do was add "die();" after the header("Location..."); call. For some reason this worked for all the IE browsers I tested. It also continued to work in Firefox. So in the code:
header("Location: http://www.google.com"); //you do not have to use an absolute path, this is just an example
die();
I don't know why that made it work, but it did, I hope that helps you. Also if you are totally stuck, another solution is to use location.href via javascript. This is a sloppier approach but it works.
Note:It goes without saying that when you develop on a local
testing server, the remote testing server could have a significantly
different configuration, so this issue may also come up if your code
errors out on the production server and you simply cannot see the
error. A symptom of this will result in a blank page, not a "Cannot
display page error". So make sure you consider production side code
errors when troubleshooting. The reason why you may not see the error
and just a blank page is because it is good practice to NOT show errors
and warnings on a production server. So a blank page is a good indicator that there is an error in your code.
Keywords: header location php, ie not working
Comments