View Full Version : Header('Location.... not always working

10-09-2003, 10:02 PM
Please help!

I am struggling with getting this to work,

header("location: " . $url);

If I put in at the top of a page like this

<?php header("location: " . $url); ?>

it works every time. But if i put it on a page with some require_once() statements above it - it works about 50% of the time. It will work 5 times in a row then every other time then maybe 10 times it won't work. It's completely random!

When I say that it doesn't work, what I mean is that it redirects as requested - but the new page doesn't show. I just get a blank screen. If I press refresh on the browser then it shows the page ok.
When I check the source for the blank screen it looks like this...

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<META http-equiv=Content-Type content="text/html; charset=windows-1252"></HEAD>

There is no whitespace in my code - this would prevent the redirect from happening at all.
The coding of the redirect is fine - as it works 50% of the time.

Can anyone help - maybe even a workaround that could cause the new page to refresh would help - but as I cant get the new page to show then the refresh code will also not work.
Is it possible to force the NEXT page to refresh??

Probably not as I am not really sure what I mean by that at all.

All help appreciated.

10-09-2003, 11:37 PM
Well by brute force (trying everything), I have solved it.

When I included the session id in the querystring it suddenly worked. It just happens that the session files were one of the require_once() included files.

I think that the MySql server was not to happy with being hit for 2 session writes in the same split second.
Now I include the session id in the redirect url and the second page doesn't have to create a new one it just verifys (reads) the id provided.

Permanent connections to the db would be a solution - but they bring their own nightmares.