I got really upset with everybody telling me that I could not do this and having to write convoluted and difficult to maintain code in order to comply with the rule that the PHP Header redirect cannot be used after the page headers have been sent. Sorry but anybody who told you that you cannot redirect pages at any time from PHP is wrong,wrong,wrong! Now you can redirect PHP pages at ANY time in a script.
Sometimes you just want to find a way around the limitations - well here is how to exit to another PHP or HTML URL from anywhere in your script. It saves an awful lot of effort especially in logout scripts or security scripts! Here is the PHP code fragment that makes it all happen.
The first line is an inline print directive that simply prints everything between it and the end flag (scendx) to the surfers web browser. Dont forget that the end flag must be at the start of the line with no space characters before or after it and should be followed by a semi-colon on the line beneath.
This places a tiny javascript fragment into the page which is the actual instantaneous redirect - it takes a standard URL and so of course can be built with query strings etc. You can even use $ variables within the print command so you could build a flexible and powerful redirection scheme from what is essentially a piece of code from a framebreaker script. Finally just in case the surfer is one of the 1% or so who browse without javascript a noscript tag is included to allow the the surfer to follow a link.
Finally the exit command wraps up the page you have started to send to the browser, making it execute the jscript redirect.
Over the last few months this has saved me from having to write some really stupidly organised code on my
web cams site and my
webmasters co-operative free advertising site and since I could not find the method elsewhere I present it here. For those of you who have never tried the inline print function then give it a go - that can save a huge amount of coding too!