tags:

views:

63

answers:

2

I need all active sessions to be destroyed when I call a certain function. This function when called needs to destory all sessions NOT immediately but after exactly 30 seconds. Even if the user leaves the page where the session was called before the 30 seconds, his browser should still be cleared of all sessions so when he comes back to the site none of those sessions will be active.

Is this possible? If so how would one go about writing such a function?

EDIT

As for why I need this, I have a shopping cart script that when submitted takes the user to paypal to process payment. If I destroy all sessions when the submit button on that payment form is clicked, I can;t pass all the form data onto paypal. If I don't destroy all sessions, when the user comes back to the site the shopping cart is still filled with the contents he purchased before.

I need the cart to be empty when the user comes back. I figured 30 seconds will give the user ample time to go to the paypal page by which point my cart script has already sent all necessary info to paypal. And then destroying all sessions is safe without fearing disruption to service.

So what I need is sort of a timer script that will work on the server side and will destroy the sessions even when the user is no longer on that page.

+1  A: 

See http://bytes.com/topic/php/answers/4134-when-how-php-session-expire-can-i-set-minutes-inactivity

Timothy
Thanks but this isn't what I need though, even if the user is idle I don't want the sessions to be destroyed, only under a certain condition I want this to be the case, and I have already written the logic to execute the function under that condition. Now all I need is the function's content :P
Vic
Use javascript to check previous url, then call your code to execute the session kill, then reload the page. Then you don't need to worry about timers at all.
Timothy
A: 

Ok, so nevermind my hairbrained sleep() approach.

Set a flag in the session, before you send them over to paypal. Check this flag and clear the session/cart if it's set.

George Marian