--- adwinwijaya <[EMAIL PROTECTED]> wrote:
> why the php didnt stop processing after sending the header? because
> in my logic ... after sending the (redirect) to another page .. the
> process shall be stopped

This might make sense to you, but only because you're thinking of header()
as a redirect function. First, you must realize that it is not. It is a
function that sets an HTTP header.

If you've worked with headers much before, you may have run into an error
that says something like this:

Warning: Cannot add header information - headers already sent by (output
started at ...) in ... on line ...

To avoid this error, people must either set the headers they want prior to
any output (often by placing calls to header() at the top), or they use
output buffering.

So, consider that you use header() at the top of your script. Now, you
want to generate an image, so your script begins like this:

<?
header('Content-Type: image/png');

The rest of the script generates the image. Wouldn't you be frustrated if
PHP decided to stop at the header() call? That would certainly frustrate
me.

Now, PHP could identify when the header() call is going to change the
status code of the response. Perhaps, if the response is going to be a
300-level response, PHP should exit afterward. But, why make such a
dangerous assumption when the developer can exit if he/she wants?

It would also break things like this:

<?
header('Location: http://default.org/');

if ($foo)
{
     header('Location: http://foo.org/');
}
elseif ($bar)
{
     header('Location: http://bar.org/');
}
?>

While this may not be eloquent, hopefully it is clear that the author
intends for the user to only get redirected to http://default.org/ if both
$foo and $bar are false. If PHP exited immediately after the first line,
this script would not behave as the developer intendend. PHP's assumption
would be wrong.

Hope that helps.

Chris

=====
Chris Shiflett - http://shiflett.org/

PHP Security - O'Reilly
     Coming mid-2004
HTTP Developer's Handbook - Sams
     http://httphandbook.org/
PHP Community Site
     http://phpcommunity.org/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to