如何在CodeIgniter中获取会话超时? [英] How to get the Session Timeout in CodeIgniter?

查看:52
本文介绍了如何在CodeIgniter中获取会话超时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在会话超时前5分钟运行功能。我的会话超时在我的配置文件中设置为7,200。

I am trying to run a function 5 minutes before a session times out. My session timeout is 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.

这篇关于如何在CodeIgniter中获取会话超时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆