10.3.4 Removing session dataThis is NOT the latest copy of this book; click here for the latest version.
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']); ?>
|
Want to see this stuff in print? PHP in a Nutshell takes the core topics covered here, adds in thousands of edits from the editorial team and myself, and combines them to make an unbeatable reference for PHP programmers at all levels.
My latest book has hundreds more tips on how to use PHP, Apache, and MySQL, plus Perl, Python, shell scripts, performance tuning, and more!
|