Breaking Session

include ‘temp107h.php’; continues the session

header(‘Location: http://localhost/temp107h.php’); breaks the session.

How can I use header() and not break the session?

session_start(); re-activates the session even without session_write_close().

then, what’s the advantage of using use session_write_close()?

“…header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP.”

From PHP.net (the first place to look for answers).

I found session_write_close() in the manual. I used it thinking it would store my session array, but all it needed was session_start(); in the script called in the header to get access to the session array again.

I just wanted continued access to the session array and I thought it would be proper to close the session array with session_write_close() before re-opening it with session_start().

why should session_write_close() matter when using session_start() continues to give me access to the session array?

session_write_close writes the session back to the session file and releases it so that another instance of your php script can access it. This is handy for example if you have a script that may take a while to complete (such as a download script) which no longer needs access to the session. In this scenario if you didn’t use session_write_close and you tried to call another script which uses session_start() then you would just see the browsers blue bar moving slowly as it heads towards a timeout. This is because session_start() cannot gain control of the session and effectively ends up in a queue.

It’s kind of like using a Critical Section in win32 languages.