session_destroy

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
nga
Forum Commoner
Posts: 46
Joined: Mon Aug 17, 2009 3:05 am

session_destroy

Post by nga »

Quick question though. Im creating a cart using session and there is an option to clear the cart and im using session_destroy to do it. However, customer would need to click clear cart twice for it to work. The first click doesnt clear anything (sessions can still be echoed) the second one does it. How can i just destroy the session after 1 click?

Im planning to use ajax to add product into the cart but the session_destroy is giving a lot of headache here too :(
User avatar
flying_circus
Forum Regular
Posts: 732
Joined: Wed Mar 05, 2008 10:23 pm
Location: Sunriver, OR

Re: session_destroy

Post by flying_circus »

It depends where you are destroying the session. After you "click the button" does your script output session data before destroying the session? This would give the perception that it takes 2 attempts to destroy a session.
nga
Forum Commoner
Posts: 46
Joined: Mon Aug 17, 2009 3:05 am

Re: session_destroy

Post by nga »

nope, im positive the damn thing needs to be clicked twice. The echoing part is the last part.
User avatar
tr0gd0rr
Forum Contributor
Posts: 305
Joined: Thu May 11, 2006 8:58 pm
Location: Utah, USA

Re: session_destroy

Post by tr0gd0rr »

When you destroy a session, you also need to clear the $_SESSION itself and delete the cookie so a new session id will be created. See the example on php.net: http://us3.php.net/session_destroy
User avatar
flying_circus
Forum Regular
Posts: 732
Joined: Wed Mar 05, 2008 10:23 pm
Location: Sunriver, OR

Re: session_destroy

Post by flying_circus »

Sure enough, thanks for picking up my slack. I forgot you had to unset the session after destroying it. :)
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Re: session_destroy

Post by Charles256 »

First time I figured that out I remember commenting in my code // die you ******* session. now. die. never again :lol:
User avatar
tr0gd0rr
Forum Contributor
Posts: 305
Joined: Thu May 11, 2006 8:58 pm
Location: Utah, USA

Re: session_destroy

Post by tr0gd0rr »

I know! PHP needs a function called session_decimate() because destroy is not strong enough :D
Post Reply