How to empty $_SESSION?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
someguyhere
Forum Contributor
Posts: 181
Joined: Sun Jul 27, 2008 3:24 pm

How to empty $_SESSION?

Post 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)
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: How to empty $_SESSION?

Post 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.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: How to empty $_SESSION?

Post by Christopher »

Are you sure the session is started when you set $_SESSION? If it is not started, it will not work.
(#10850)
someguyhere
Forum Contributor
Posts: 181
Joined: Sun Jul 27, 2008 3:24 pm

Re: How to empty $_SESSION?

Post by someguyhere »

requinix wrote:session_destroy will destroy the data.
Worked like a charm! Thank you!
Post Reply