Page 1 of 1

How to empty $_SESSION?

Posted: Wed Aug 14, 2013 2:14 pm
by someguyhere
I have a script that accepts input and then outputs a report based on that. Everything is stored in $_SESSION, but I can't seem to unset or empty the variable at the end of the script, which is preventing people from re-running the script.

I've tried

unset ( $_SESSION );

as well as

$_SESSION = NULL;

But neither accomplish my goal. Is there another way? Or do I have to manually delete every single element of the array? :banghead:

(If it makes a difference, this is running inside Wordpress)

Re: How to empty $_SESSION?

Posted: Wed Aug 14, 2013 2:20 pm
by requinix
I believe both of those don't work because they merely touch the "$_SESSION" variable. The data is still intact - you just can't access it anymore.

session_destroy will destroy the data.

Re: How to empty $_SESSION?

Posted: Wed Aug 14, 2013 2:29 pm
by Christopher
Are you sure the session is started when you set $_SESSION? If it is not started, it will not work.

Re: How to empty $_SESSION?

Posted: Wed Aug 14, 2013 3:22 pm
by someguyhere
requinix wrote:session_destroy will destroy the data.
Worked like a charm! Thank you!