[nycphp-talk] Header() Redirect!!
David Krings
ramons at gmx.net
Thu Jun 11 22:07:58 EDT 2009
tuon1 at netzero.net wrote:
> |<html>
> <?php
> /* This will give an error. Note the output
> * above, which is before the header() call */
> header('Location: http://www.example.com/');
> ?>|
> ||
> |If this statement is true, then how do you use header() function in any
> script that does not contain any "normal HTML tags" since you typically
> have to output something, whether before or after the call to the header()?|
The way I use header redirects is by first having a script that generates
output and includes some sort of a form (can even be a static page). That form
gets submitted to a script that evaluates the parameters and values passed and
based on that redirects to other scripts that generate particular content.
So yes, there is a good possibility that the script using the redirect never
generates any output. BUT, some craft their applications using only a few
files that each are a huge switch statement with various blocks of code. In
those cases the first block can very well generate output whereas the second
block has the redirects. It is just that when the second block gets called the
first block is not executed. So it doesn't matter what comes first within the
script, but what ultimately gets sent to the browser first.
By the time the browser displays something it already got the header. So since
the header is already sent you cannot modify it any longer. It's like trying
to sign a check that you mailed yesterday and that the recipient already received.
David
More information about the talk
mailing list