1. Technology
Send to a Friend via Email

Your suggestion is on its way!

An email with a link to:


was emailed to:

Thanks for sharing About.com with others!

You can opt-out at any time. Please refer to our privacy policy for contact information.

Basic PHP Sessions


3 of 3

Modify or Remove a Session
 // you have to open the session to be able to modify or remove it 
 // to change a variable, just overwrite it 
 //you can remove a single variable in the session 
 // or this would remove all the variables in the session, but not the session itself 
 // this would destroy the session variables 
The code above demonstrates how to edit or remove individual session variables, or the entire session. To change a session variable we just reset it to something else. We can use unset() to remove a single variable, or session_unset() to remove all variables for a session. We can also use session_destroy() to destroy the session completely.

By default a session lasts until the user closes their browser. This can be changed in the php.ini file by change the 0 in session.cookie_lifetime = 0 to be the number of seconds you want the session to last, or by using session_set_cookie_params().

Related Video
Basic PHP Syntax
Using PHP With HTML
  1. About.com
  2. Technology
  3. PHP / MySQL
  4. Advanced PHP
  5. Basic PHP Sessions - Modify or Remove a Session

©2014 About.com. All rights reserved.