修改 CakePHP 会话的会话 cookie 到期和会话超时 [英] Modify session cookie expiry and session timeout for a CakePHP session
问题描述
我正在努力完成以下工作:根据用户的类型更改用户的会话 cookie 到期日期.
I'm struggling to accomplish the following: Alter the user's session cookie expiry date based on the user's type.
我有一个 CakePHP Web 应用程序,其中我使用 CakePHP 会话创建了我的身份验证组件(而不是 CakePHP 的 Auth).我已经将 CakePHP 配置为使用数据库处理会话.
I have a CakePHP web application wherein I have created my authentication component (instead of CakePHP's Auth) using CakePHP sessions. I've configured CakePHP to handle sessions using the database.
以下是我在 config.php 中的相关配置设置:
Here are the relevant configuration settings that I have in my config.php:
Configure::write('Session.save', 'database');
Configure::write('Session.timeout', '36');
Configure::write('Security.level', 'medium');
如何延长会话 cookie 的到期日期并更新 "sessions" 表中 "expires" 列中的值?
How do I extend the session cookie expiry date AND update the value in the "expires" column in the "sessions" table?
推荐答案
进入 app/config/core.php
Go in app/config/core.php
在这个文件中搜索,
Configure::write('Session.timeout', '120');
会话超时时间(以秒为单位),默认为 120 秒.您可以根据需要在此处进行编辑.现在实际超时持续时间取决于,
Session time out time (in seconds), by default it is 120 seconds. You can edit it here as required. Now the actual timeout duration depends on,
Configure::write('Security.level', 'medium');
if 'high' then Session timeout in 'Session.timeout' x 10,
if 'medium' then Session timeout in 'Session.timeout' x 100,
if 'low' Session timeout in 'Session.timeout' x 300
因此通过 Session.timeout 和 Security.level 的组合,您可以获得所需的会话超时
So by combination of Session.timeout and Security.level you can get the desired session timeout
这篇关于修改 CakePHP 会话的会话 cookie 到期和会话超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!