Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sessions

Status
Not open for further replies.

axman505

Technical User
Jun 20, 2001
489
US
can anyone offer any help or pooint me in the right direction to figureing out seesions?
 
Sessions in PHP are no where near as tough as you're thinking they are.

At the beginning of any script that is going to use session variables, issue session_start().

Any variable that you want to use as a session variable, use session_register() on the name of that variable. For example, if you have a variable called $username, perform session_register("username").

Once a variable has been registered with a session, it will be available as $_SESSION["username"] if you have "register_globals" set to "off" in php.ini, and both in $_SESSION["username"] and as $username if "register_globals" is set to "on".

Once your done with a particular session variable, perform session_unregister("username").

For more details, read ______________________________________________________________________
TANSTAAFL!
 
the part that has me confused is when im going from the login page to the other pages. And how to verify a user is logged in when loading theother pages so you cannot just do a direct call to it and have it work.
 
What I've done is have the login page, once the user's credentials are verified, set a session variable called "login_id", which is the auto_increment ID for that user's record in the user table.

When later pages issue sestion_start(), they can then check for the presence of $_SESSION["login_id"] to know whether the user is correctly logged in, and use that variable's value to know who the user is. Conversely, if the variable does not exist, other pages can redirect the browser to the login page.
______________________________________________________________________
TANSTAAFL!
 
One gotha...

Sessions do expire. If the user is logged in and the session expires, the site will forget who he is. You need to make sure your scripts can handle this gracefully. ______________________________________________________________________
TANSTAAFL!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top