How to increase cakephp Auth component session expire time

Shaiful Islam picture Shaiful Islam · Jun 7, 2015 · Viewed 11.1k times · Source

I am using Auth component to check user is logged in.

Here is my AppController's initialize function

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'
        ]
    ]);
}

Its working fine.But if I stay inactive for few minutes(like 3-5min) and go(click) to a link it sends me login page.It seems session time expired.

How or Where I can increase this time.

Answer

Deyson picture Deyson · Jun 8, 2015

Auth component shares Session class

For Cakephp3

At config/app.php we can set the timeout.

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

For Cakephp2

in your Config/core.php

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