Unsetting Variables and Destroying the Session

When you are finished with a session variable, you can unset it.You can do this directly
by unsetting the appropriate element of the $_SESSION array, as in this example:
unset($_SESSION[‘myvar’]);
Note that the use of session_unregister() and session_unset() is no longer
required and is not recommended.These functions were used prior to the introduction
of $_SESSION.
You should not try to unset the whole $_SESSION array because doing so will effectively
disable sessions.To unset all the session variables at once, use
$_SESSION = array();
When you are finished with a session, you should first unset all the variables and
then call  session_destroy();
to clean up the session ID.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s