CakePHP - 会话超时 [英] CakePHP - session timeout

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

问题描述

我在core.php中使用在30分钟后退出:

 配置:: write (
'defaults'=>'php',
'timeout'=> 30,// 30分钟后自动注销
'cookieTimeout'=> 1440,//会话cookie 24小时
'autoRegenerate'=> true //重新生成会话
));

这工作很好。并且我会显示会话超时的倒计时消息,例如在注销按钮旁边的页眉中。有人帮助我吗?



例如在default.ctp。

 < body> 
< div id =container>
< div id =header>
< div style =float:right;>
<?php

//显示会话超时的倒计时:
//您将被自动注销(超时时间到)cookie
$ b //退出按钮
echo $ this-> Html-> link(__('Logout'),array('controller'=>'users','action'=>'logout' ),array('escape'=> false));
?>
< / div>
< / div>
< div id =content>

< / div>
< / div>

解决方案>

由于人们对你很苛刻,这是你第一次来这里,我会有点温柔。我不提供您的答案,但关键指标:




  • 您可以阅读 $ this- - > read('Config.time')以获取会话何时结束的unix时间戳。

  • http://momentjs.com> moment.js 非常适合操作时间,倒计时等。检查 fromNow - 您可以将其用于未来。



    • 希望这有帮助;)


      I use in core.php for logout after 30 minutes this:

      Configure::write('Session', array(
          'defaults' => 'php',
          'timeout' => 30,            // auto logout after 30 minutes
          'cookieTimeout' => 1440,    // session cookie 24 hours
          'autoRegenerate' => true    // regenerate session
      ));
      

      This work fine. And I would to display countdown message of session timeout, for example in header of page next to the logout button. Could anybody help me?

      For example in default.ctp.

      <body>
      <div id="container">
          <div id="header">
              <div style="float: right;">
                  <?php
      
               // display countdown of session timeout:
               // You will be automatically logged off for (time to expire cookie timeout)
      
                  // Logout button    
                  echo $this->Html->link(__('Logout'), array('controller' => 'users', 'action' => 'logout'), array('escape' => false));
                  ?>
              </div>
          </div>
          <div id="content">
      
          </div>
      </div>
      

      解决方案

      Since people are harsh on you and this is your first time here, I shall be a little bit gentle on this. I don't provide you the answer, but key pointers:

      • You can read $this->Session->read('Config.time') to get the unix timestamp of when will be the session ends.
      • Some javascript library like moment.js is great in manipulating time, countdown etc. Check fromNow - you can use it for future too.

      Hope this helps ;)

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

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