NYCPHP Meetup

[nycphp-talk] Disappearing $_SESSION variables after using header ()

Michael Southwell michael.southwell at nyphp.com
Mon Nov 24 23:01:08 EST 2008


Tony Furnivall wrote:
> Many thanks to  [csnyder] and [Tim Lieberman] for their helpful 
> suggestions about header ().
> 
> I now have that part of things working fine. However, because there is 
> an implicit exit; after issuing the call to header (), I'm uncertain if 
> the $_SESSION variables are being set properly.
> 
> When I trace them at the end of one page they are all there 
> ($_SESSION['userid'] = $userid; $_SESSION['badgename']=$badgename;), but 
> when I examine the $_SESSION array at the start of the next page, the 
> variables do not exist. My guess is that by short-circuiting any nrmal 
> end-of-script processing, I may be bypassing the write of the $_SESSION 
> array to the temporary file.

They've already been written; what you're doing is losing the 
identification of the session, so they can't be found. So when you use 
the header command, you need to carry along the session id as a GET 
variable, like this:
header( 'Location:somepage.php?PHPSESSID=' . session_id() );


-- 
=================
Michael Southwell
Vice President, Education
NYPHP TRAINING:  http://nyphp.com/Training/Indepth



More information about the talk mailing list