CodeIgniter Forums
Expire Session When Not Active - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forum-5.html)
+--- Forum: General Help (https://forum.codeigniter.com/forum-24.html)
+--- Thread: Expire Session When Not Active (/thread-67942.html)



Expire Session When Not Active - arisroyo - 04-28-2017

Sleepy

I would like to ask on how to automatically expired user session when it's not active?
I find out that CI never expire it's session and when I tried to make $config['sess_time_to_update'] lower than $config['sess_expiration']
it expired even if the user is actively using the web application.

Thanks in advance.


RE: Expire Session When Not Active - InsiteFX - 04-28-2017

PHP Code:
$config['sess_expiration'] = 0// Session will expire on web browser close. 



RE: Expire Session When Not Active - muuucho - 04-28-2017

(04-28-2017, 04:50 AM)arisroyo Wrote: Sleepy

I would like to ask on how to automatically expired user session when it's not active?
I find out that CI never expire it's session  and when I tried to  make $config['sess_time_to_update']  lower than $config['sess_expiration']
it expired even if the user is actively using the web application.

Thanks in advance.

Or maybe something like this in MY_Controller if yu like to kick out people who are inactive (=makes no requests):
http://stackoverflow.com/questions/9124560/how-to-expire-php-session-if-user-is-inactive-for-15-mins
Depends what you mean with "not active".


RE: Expire Session When Not Active - arisroyo - 04-29-2017

Thanks to both of you that helps a lot.

The logic is if user is keep using the web application the session must continue and if inactive for 15 minutes for the session should be expired even without closing the browser.

So I combine PHP.ini session configuration with CI session configuration

PHP.ini Session Configuration

session.gc_maxlifetime = 900 (15 minutes)

CodeIgniter Configuration

$config['sess_expiration'] = 900; (15 Minutes)
$config['sess_time_to_update'] = 450; (7 half minutes for update)


RE: Expire Session When Not Active - InsiteFX - 04-29-2017

If you need to check the time then you would need to use a javascript timer event for check like that,
then you could just have the sessions not expire until browser close. If you need to keep them logged it
then you could do an autoload user on web site access using a remember me cookie.


RE: Expire Session When Not Active - muuucho - 04-29-2017

I think you should be OK by setting time() in a sesssion on each request. Every new request compares time() with the timestamp you put in the session on the old request. If the diff is >15 min, kick the user out by destroying and unset the session, If the diff is < 1 min overwtire the session with the new time().


RE: Expire Session When Not Active - skunkbad - 04-29-2017

With database sessions, you could always do a delete query for timestamps older than X mins. Run this via cron every minute or whenever you feel like it.