Session Question
Moderator: General Moderators
Session Question
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?
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
- technofreak
- Forum Commoner
- Posts: 74
- Joined: Thu Jun 01, 2006 12:30 am
- Location: Chennai, India
- Contact:
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.
Actually, when you initialize a session variable by declaring it as,
Code: Select all
$_SESSION['user'] = $user;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.