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']); ?>
If this was helpful, please take a moment to tell others about Hacking with PHP by tweeting about it!
Next chapter: Ending a session >>
Previous chapter: Reading session data
Home: Table of Contents
Copyright ©2015 Paul Hudson. Follow me: @twostraws.