NYCPHP Meetup

NYPHP.org

[nycphp-talk] simple problem with sessions

Chris Shiflett shiflett at php.net
Sat Oct 9 19:28:46 EDT 2004


--- Jeff Siegel <jsiegel1 at optonline.net> wrote:
> But wouldn't it be the case that the user has already been
> redirected to a different page before the script has terminated?
> That is, when the code is:
> 
> header('Location: otherpage.php');
> exit;

Nope, because until the script terminates, no response is sent. The
header() function only sets an HTTP header within the response, although
Location is a special header in which case PHP also changes the response
status code.

The browser requests the new URL (which should be specified in the
Location header using an absolute URL) once it receives the response, but
prior to that, it has no idea that it's coming.

So, I've been wondering if this suggestion to use session_write_close()
came about because of this misunderstanding about how the header()
function works or something. That's my only guess, unless there is a
special case that I'm unaware of.

Chris

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

PHP Security - O'Reilly     HTTP Developer's Handbook - Sams
Coming December 2004        http://httphandbook.org/



More information about the talk mailing list