Jump to content

Emptying $_SESSION arrays


jamesjmann

Recommended Posts

I already know how to empty individual $_SESSION[""] array elements, but I was wondering how you could empty ALL $_SESSION array elements without having to write out unset ($_SESSION[""]); for each one?

 

Is it just unset ($_SESSION);?

 

Sorry if this seems like a stupid question, but I'm just trying to make sure, because I have a lot of $_SESSION variables and am trying to simplify the task of emptying them all.

Link to comment
Share on other sites

session_unset();

session_destroy();

 

 

.................. google next time

 

I'm pretty sure phpfreaks.com was meant for questions like this. Why would I sign up on phpfreaks if I could just google all the answers to my questions?

 

 

Sorry if you took that little comment to harsh, but when i google unset sessions, PHP.net is the first hit with the correct answer.

PHP.net has basically all the solutions to problems like this, because they are so basic and fundamental.

Link to comment
Share on other sites

session_unset();

session_destroy();

 

 

.................. google next time

 

I'm pretty sure phpfreaks.com was meant for questions like this. Why would I sign up on phpfreaks if I could just google all the answers to my questions?

 

It's actually part of the forum rules.

 

Users will attempt to find answers to their questions by the following before posting:

 

  1. Search PHP Freaks Forum for the answer. Chances are this question has been asked before.

  2. Search the PHP Manual for a function and or information about a function to fix the error or achieve the desired results.

  3. Search Google for an answer to their question. As stated, it has probably been asked and solved many times before.

Link to comment
Share on other sites

I'm not aware of any rule that only moderators can correct members.  There's also no rule that members can tell other members what to do.  So I would say common sense and politeness should take priority here.  Especially since he gave you the wrong answer, it would have been better if he said "I found this on google" rather than "google next time".

Link to comment
Share on other sites

I'm not aware of any rule that only moderators can correct members.  There's also no rule that members can tell other members what to do.  So I would say common sense and politeness should take priority here.  Especially since he gave you the wrong answer, it would have been better if he said "I found this on google" rather than "google next time".

 

It should be a rule. Its very rude to make comments like that, and I'm not going to lie, he made me feel stupid lol, which p***ed me off.

Link to comment
Share on other sites

This is all off topic so drop it.

 

... Especially since he gave you the wrong answer, it would have been better if he said "I found this on google" rather than "google next time".

 

I wouldnt say the answer i gave was wrong.. The q was how to unset all sessions, and the two functions i listed does exactly that, am i right? So go somewhere else being a smartypant, Mr. Smartypants :-) :-)

Link to comment
Share on other sites

nicholasolsen, please see the following on the manual page for session_unset():

 

If $_SESSION (or $HTTP_SESSION_VARS for PHP 4.0.6 or less) is used, use unset() to unregister a session variable, i.e. unset ($_SESSION['varname']);.

 

As the OP was using $_SESSION (and most PHP installations these days do), session_unset() is not the correct function to use.  Also, the session_destroy() manual page says that session_unset() is deprecated, and specifically instructs to use it only for code that does not use $_SESSION.

 

Edit: I would also like to point out that these are the things you won't find easily by using google.

Link to comment
Share on other sites

nicholasolsen, please see the following on the manual page for session_unset():

 

If $_SESSION (or $HTTP_SESSION_VARS for PHP 4.0.6 or less) is used, use unset() to unregister a session variable, i.e. unset ($_SESSION['varname']);.

 

As the OP was using $_SESSION (and most PHP installations these days do), session_unset() is not the correct function to use.  Also, the session_destroy() manual page says that session_unset() is deprecated, and specifically instructs to use it only for code that does not use $_SESSION.

 

Edit: I would also like to point out that these are the things you won't find easily by using google.

 

 

However, it does the trick.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.