By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,825 Members | 1,462 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,825 IT Pros & Developers. It's quick & easy.

best method for unsetting a whole session

P: n/a
sg
Hi,

I use sessions on my site and i have an admin page where I want to be able
to unset all session variables and destroy the session.

for the moment I do :
<?
session_unset();
session_destroy();
?>

This works perfectly fine for me.

BUT (yes this post has a point)

I just saw in the PHP Manual (for 'session_unset()')
"Note: If $_SESSION (or $HTTP_SESSION_VARS for PHP 4.0.6 or less) is used,
use unset() to unregister session variable. i.e. $_SESSION = array();"

As a matter of fact I am using the $_SESSION superglobal to manipulate my
session variables. So I think this applies to me but I don't really
understand how I should unset my session variables. And the unset() manual
page doesn't really help me either.

Can somebody clear that up for me?

Sebastien
Jul 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
"sg" <sg******@freesurf.fr> wrote in message news:<bn**********@news-reader1.wanadoo.fr>...
Hi,

I use sessions on my site and i have an admin page where I want to be able
to unset all session variables and destroy the session.

for the moment I do :
<?
session_unset();
session_destroy();
?>

This works perfectly fine for me.

BUT (yes this post has a point)

I just saw in the PHP Manual (for 'session_unset()')
"Note: If $_SESSION (or $HTTP_SESSION_VARS for PHP 4.0.6 or less) is used,
use unset() to unregister session variable. i.e. $_SESSION = array();"

As a matter of fact I am using the $_SESSION superglobal to manipulate my
session variables. So I think this applies to me but I don't really
understand how I should unset my session variables. And the unset() manual
page doesn't really help me either.


If you use $_SESSION superglobal,
use $_SESSION = array(); to unset the whole session array
use unset($_SESSION['foo']) to unset foo of session array.

But, don't use unset($_SESSION) to unset the whole session array.

So, for in your case, use
$_SESSION = array(); //instead of session_unset();
session_destroy(); //destroy

---
"He who created the god was a fool; he who spreads his name is a
scoundrel and he who worships him is a barbarian."---Periyar, Famous
Tamil Rationalist
Email: rrjanbiah-at-Y!com
Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.