【问题标题】:How to increase cakephp Auth component session expire time如何增加 cakephp Auth 组件会话过期时间
【发布时间】:2015-06-07 14:54:49
【问题描述】:

我正在使用 Auth 组件来检查用户是否已登录。

这是我的 AppController 的初始化函数

public function initialize()
{
    parent::initialize();
    $this->loadComponent('Flash');
    $this->loadComponent('Auth', [
        'authenticate' => [
            'Form' => [
                'fields' => [
                    'username' => 'username',
                    'password' => 'password'
                ],
                'passwordHasher' => [
                    'className' => 'Md5',//My own password hasher
                ]
            ]
        ],
        'loginAction' => [
            'controller' => 'Dashboard',
            'action' => 'login'
        ]
    ]);
}

它工作正常。但如果我保持不活动几分钟(如 3-5 分钟)并转到(单击)到一个链接,它会向我发送登录页面。看来会话时间已过期。

我可以如何或在哪里增加这个时间。

【问题讨论】:

    标签: php cakephp cakephp-3.0


    【解决方案1】:

    Auth 组件共享 Session 类

    对于 Cakephp3

    在 config/app.php 我们可以设置超时时间。

    'Session' => [
        'defaults' => 'php',        
        'timeout'=>24*60//in minutes
    ],
    

    对于 Cakephp2

    在你的 Config/core.php 中

    Configure::write('Session', array(
        'defaults' => 'php',
        'timeout' => 31556926 //increase time in seconds
    ));
    

    【讨论】:

    • 嗨,是否可以增加应用控制器或任何其他控制器中的会话时间。因为我在管理面板中动态更改会话时间。使用 cake php3
    • @RaghulRajendran 是的,你可以。检查此链接book.cakephp.org/3.0/en/development/sessions.html
    【解决方案2】:

    Auth 组件共享 Session 类。对于 CakePHP 3,您可以在 config/app.php 设置会话超时,如下所示:

    'Session' => [
            'defaults' => 'php',
            'timeout'  => 1440, /*24 hours*/
        ],
    

    【讨论】:

    • 为什么要使用块注释 /* */ 而不是使用行注释 // 或 # ;)
    猜你喜欢
    • 2017-11-26
    • 2019-09-27
    • 2018-06-05
    • 1970-01-01
    • 1970-01-01
    • 2013-01-28
    • 2011-07-11
    • 2015-01-17
    • 1970-01-01
    相关资源
    最近更新 更多