开发者

How to get the Session Timeout in CodeIgniter?

I am trying to run a function 5 minutes before a session times out. My session timeout i开发者_C百科s set to 7,200 in my config file. Is it possible to do this with CodeIgniter?


I think you're 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's destroyed, as pointed out by
       coolgeek. */

    // ... Do some stuff
}

You would probably want to run this inside of a hook (see the hook docs here) so that it runs on every page load before or after controllers are run, depending on what you're trying to do.


A session times out if there are no requests (page hits) within the timeout period. As such, a php solution will not solve the problem.

You need to put a javascript timer in your page that will count down from the time that the page was requested and take some action once it reaches the (timeout - 5 minutes) threshold.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜