Page 1 of 1
session_destroy
Posted: Thu Jan 14, 2010 1:22 am
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

Re: session_destroy
Posted: Thu Jan 14, 2010 1:26 am
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.
Re: session_destroy
Posted: Thu Jan 14, 2010 4:31 am
by nga
nope, im positive the damn thing needs to be clicked twice. The echoing part is the last part.
Re: session_destroy
Posted: Thu Jan 14, 2010 11:11 am
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
Re: session_destroy
Posted: Thu Jan 14, 2010 12:39 pm
by flying_circus
Sure enough, thanks for picking up my slack. I forgot you had to unset the session after destroying it.

Re: session_destroy
Posted: Thu Jan 14, 2010 12:44 pm
by Charles256
First time I figured that out I remember commenting in my code // die you ******* session. now. die. never again

Re: session_destroy
Posted: Thu Jan 14, 2010 2:56 pm
by tr0gd0rr
I know! PHP needs a function called session_decimate() because destroy is not strong enough
