1. Computing

Basic PHP Sessions

By

3 of 3

Modify or Remove a Session
 <?php 
 // you have to open the session to be able to modify or remove it 
 session_start(); 
 
 // to change a variable, just overwrite it 
 $_SESSION['size']='large'; 
 
 //you can remove a single variable in the session 
 unset($_SESSION['shape']); 
 
 // or this would remove all the variables in the session, but not the session itself 
 session_unset(); 
 
 // this would destroy the session variables 
 session_destroy(); 
 ?> 
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. Computing
  3. PHP / MySQL
  4. Advanced PHP
  5. PHP End Session - PHP Remove Session - PHP Delete Session

©2014 About.com. All rights reserved.