Page 1 of 1
Session Question
Posted: Mon Jun 19, 2006 5:10 pm
by Bigun
If you start a session on one page, save the info into the session, would it be necessary to call session_start again on the next page to recall that information?
Posted: Mon Jun 19, 2006 5:16 pm
by Weirdan
yes
Posted: Mon Jun 19, 2006 5:42 pm
by RobertGonzalez
Yes, always. Anytime you are using session data on a page you need to start the page with session_start() (unless you use auto_session_start [i think?!?!?] in php.ini).
Posted: Mon Jun 19, 2006 5:44 pm
by Christopher
In simplest terms -- calling session_start() loads the session data for that "user" into the $_SESSION superglobal array.
So the $_SESSION array will not exist until session_start() is called.
Posted: Tue Jun 20, 2006 12:28 am
by technofreak
Yes, the session_start() should be included at the first line of all the pages where you wish to make use of the variable declared as session variables, $_SESSION[].
Actually, when you initialize a session variable by declaring it as,
The session variable gets written in a file which is stored in a particular location in your PHP directory ( like C:/PHP/temp) Everytime a session is created, a new file is created where the session variables are stored. When you use a session_start() at the beginning of the code, the session variables are made available from the global session array (contents of this file) to the code to follow. The files exists till the session exists ( can be killed with session_destroy() function) and the contents can be unset using the unset() function.
This is very helpfull to find whether your session variable declarations are working properly, by checking the contents of the corresponding session file. Files are usually named after a unique session id.