Destroy session once the browser is closed |
Please help me to destroy the session once my browser is closed in Codeigniter 3.
Since the http protocol is a stateless protocol https://en.wikipedia.org/wiki/Stateless_protocol there is no way of knowing if a end user has actually "left" your web site.
Therefore PHP has session.gc_maxlifetime http://php.net/manual/en/session.configu...axlifetime which specifies the number of seconds after which data will be seen as 'garbage' and potentially (based on a few other factors) cleaned up. This value is also used in conjunction with CodeIgniter's session configuration value "sess_expiration" http://www.codeigniter.com/user_guide/li...references. You could attempt some ajax trickery but, I personally think it's a waste of time since PHP and CodeIgniter already have something in place. DMyers
You can send an AJAX request onunload but they won't always reach your server. You could use a socket.io server and delete the session in the disconnect event if you're using Redis as your session library and store the users session ID on the socket.
Unless its imperative the session is deleted I would rely on PHP's garbage collector. |
Welcome Guest, Not a member yet? Register Sign In |