How to get session timeout in CodeIgniter?

I am trying to run a function 5 minutes before the session expires. My session timeout is set to 7,200 in my configuration file. Can this be done with CodeIgniter?

+4
source share
2 answers

I think you are looking for something like this:

$lastActivity = $this->session->userdata('last_activity'); $timeOut = time() - 7200 + 300; // now minus the the session // timeout plus 5 minutes if ($lastActivity <= $timeOut) { /* This runs on or after the "5 minutes before mark", but won't run if the session has expired. After the session times out, based on the $config['sess_expiration'] var, it destroyed, as pointed out by coolgeek. */ // ... Do some stuff } 

You probably want to run this inside the hook ( see the error documentation here ) so that it runs every time the page loads before or after the controllers start, depending on what you are trying to do.

+10
source

Session time if there are no requests (page views) during the timeout. So php solution will not solve the problem.

You need to put a javascript timer on your page, which will be counted from the moment the page is requested and take some action after reaching the threshold (timeout - 5 minutes).

+2
source

Source: https://habr.com/ru/post/1344451/


All Articles