Reputation: 4233
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.
Upvotes: 2
Views: 5425
Reputation: 1109
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.
Upvotes: 0
Reputation: 2900
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.Upvotes: 2
Reputation: 4529
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.
Upvotes: 3
Reputation: 26
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.
Upvotes: -1