我在core.php中使用30分钟后注销这个:
Configure::write('Session', array(
'defaults' => 'php',
'timeout' => 30, // auto logout after 30 minutes
'cookieTimeout' => 1440, // session cookie 24 hours
'autoRegenerate' => true // regenerate session
));
这很好。我想显示会话超时的倒计时消息,例如在注销按钮旁边的页面标题中。有人能帮我吗?
例如在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>
既然人们对你很苛刻,而且这是你第一次来这里,我对此会稍微温和一点。我不给你答案,但关键提示:
- 您可以读取
$this->Session->read('Config.time')
以获得会话何时结束的unix时间戳 - 像
moment.js
这样的javascript库在操作时间、倒计时等方面非常出色。检查fromNow
——你也可以在将来使用它
希望这能有所帮助;)
为此,您可以像一样编写
配置::写入("会话超时","120");
配置::写入("安全级别"、"中等");
如果"高",则"会话超时"x 10中的会话超时,
如果"中等",则"会话超时"x 100中的会话超时,
如果"会话超时"x 300 中的"低"会话超时
这也可能是php设置的问题。
这里有一个SO答案,详细说明了如何绕过这个问题:
https://stackoverflow.com/a/3585057/1291499