Removing session data

Removing a specific value from a session is as simple as using the function unset(), just as you would for any other variable. It is important that you should unset only specific elements of the $_SESSION array, not the $_SESSION array itself, because that would leave you without any way to manipulate the session data at all.

To extend the previous script to remove data, use this:

<?php
    $_SESSION
['foo'] = 'bar';
    print
$_SESSION['foo'];
    unset(
$_SESSION['foo']);
?>

 

Next chapter: Ending a session >>

Previous chapter: Reading session data

Jump to:

 

Home: Table of Contents

Follow us on Identi.ca or Twitter

Username:   Password:
Create Account | About TuxRadar