使用CakePHP阻止Ajax调用更新会话超时 [英] Prevent ajax calls from updating session timeout with CakePHP

查看:102
本文介绍了使用CakePHP阻止Ajax调用更新会话超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在这种JavaScript中使用一些长池:

I'm using some long pooling in JavaScript of this kind:

setInterval(demo, 3000);

function demo(){
    $.get(url, params, function(data){
        //whatever
    });
}

url成为CakePHP控制器操作的URL,该操作返回JSON.

Being url a URL to a CakePHP controller action returning JSON.

但是我希望会话自用户上一次在屏幕上执行操作以来仅持续20分钟.这是忽略每30秒发生一次池化. 否则,会话将永远持续下去.

But I want my session to only last 20 minutes since the user last action on the screen. This is, ignoring the pooling which is taking place every 30 seconds. Otherwise the session will last forever.

有什么解决办法吗?

推荐答案

请在beforeFilter函数的应用程序控制器中使用此

Please use this in app controller in beforeFilter function

if(!$this->request->is('ajax')){
             $LastActivity = $this->Session->read('LastActivity');
             if ($LastActivity != '' && (time() - $LastActivity) > 1200) {//for 20 minute
                $this->Auth->logout();
                $this->redirect('/');
            }
             $this->Session->write('LastActivity', time());
            }

这篇关于使用CakePHP阻止Ajax调用更新会话超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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