Page 1 of 1

Session Vars not staying

Posted: Tue Apr 22, 2008 4:27 pm
by desius
This is a very simple newb issue I'm struggling with... I'm trying to set a session variable and keep it on subsequent page accesses. So I use the following:

Code: Select all

 
session_start();
$_SESSION['myVar'] = $myData;
 
It's working fine on the first page visit, but anytime someone goes to the next page, the variable isn't there. Why? What is wrong here?

Re: Session Vars not staying

Posted: Tue Apr 22, 2008 5:02 pm
by Christopher
You must call session_start() on every page that uses $_SESSION. The function session_start() is what loads the data into the $_SESSION array.

Re: Session Vars not staying

Posted: Tue Apr 22, 2008 6:24 pm
by desius
Sweet, thnx for the help, I'll give this a shot immediately. Will I need to register the session variable on the new page before using it or anything like that?

Re: Session Vars not staying

Posted: Tue Apr 22, 2008 7:14 pm
by Christopher
Yes. $_SESSION is empty until you call session_start().