I need to close a session when the browser is closed, when it crashes, when a PC restarts, and so on.
I know there is cookie solution, but I need something secure, server side, because the user can delete the cookie.
I need to close a session when the browser is closed, when it crashes, when a PC restarts, and so on.
I know there is cookie solution, but I need something secure, server side, because the user can delete the cookie.
You dont have to. The garbage collector will clean up your sessions.
The php ini setting session.gc_maxlifetime
determins how long a session can remain active.
When this value is exceeded the session is automatically removed.
This can not be done the way you imagine it. You can not directly react to such an event in php. The closest you can get is using ajax to keep the session alive.
yourdomain.com/api/pulse.php
every 60 seconds.Hi You don't need to close session. because its default behavior of session that it destroy the session when user close the browser. And we can alter this behavior by changing lifetime of session in php.ini file by doing session.cookie_lifetime = 0. Otherwise by default when you reopen the browser there will be no data in session.
cookie delete automatic when user run crashed brouser.
in php no way to know when user close brouser.
some not easy way it's websocket and long poling connections, but it's not easy to configuration and not good idea.