Welcome Guest, Not a member yet? Register   Sign In
Destroy session once the browser is closed
#1

Please help me to destroy the session once my browser is closed in Codeigniter 3.
Reply
#2

(This post was last modified: 05-30-2016, 03:34 AM by dmyers.)

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
Reply
#3

(This post was last modified: 06-01-2016, 05:52 AM by spjonez.)

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.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB