How to end sessions after a certain amount of time in PHP?

I need all active sessions to be destroyed when I call a specific function. When called, this function should destroy all sessions NOT immediately, but after exactly 30 seconds. Even if the user leaves the page on which the session was called up to 30 seconds, his browser should still be cleared of all sessions, so when he returns to the site, none of these sessions will be active.

Is it possible? If so, how could one write such a function?

EDIT

As for why I need it, I have a shopping cart with a script, which, when sent, takes the user to paypal to process the payment. If I destroy all sessions when the submit button in this payment form is clicked, I cannot transfer all the form data to paypal. If I do not destroy all the sessions when the user returns to the site, the shopping basket is still filled with the content that he purchased earlier.

I need the cart to be empty when the user returns. I decided that 30 seconds would give the user enough time to go to the PayPal page, by which my basket script had already sent all the necessary information to paypal. And then the destruction of all sessions is safe, without fear of disrupting the service.

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

+3
source share
2 answers

Okay, so never mind my approach using hairbrained sleep ().

Set the flag in the session before sending it to paypal. Check this flag and empty the session / recycle bin, if installed.

0
source

Source: https://habr.com/ru/post/1755219/


All Articles