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:

    $_SESSION['foo'] = 'bar';
    print $_SESSION['foo'];


Next chapter: Ending a session >>

Previous chapter: Reading session data

Jump to:


Home: Table of Contents

Copyright ©2015 Paul Hudson. Follow me: @twostraws.