PHP Developers Cookbook (2nd Edition)

You need to remove a session variable or unregister it before script execution ends.

Technique

Use PHP's session_unregister() function instead of unset() to remove the variable from the session:

<?php session_register('somevar'); if (session_is_registered('somevar')) { session_unregister('somevar') or die('Could not unregister somevar'); } ?>

Comments

The session_unregister() function removes the specified variable from the session registry, so that when the session is saved, it will not contain the newly unregistered variable. This function does not delete the variable's contents, however.

Категории