1. Home
  2. Computing & Technology
  3. PHP / MySQL

Basic PHP Sessions

By , About.com Guide

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().

Explore PHP / MySQL
About.com Special Features

The Best Web Trends of the Decade

A look back at the best innovations, ideas and technologies over the last 10 years, More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. PHP / MySQL
  4. Advanced PHP
  5. PHP End Session - PHP Remove Session - PHP Delete Session

©2009 About.com, a part of The New York Times Company.

All rights reserved.