Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to increase cakephp Auth component session expire time

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.

like image 572
Shaiful Islam Avatar asked Jun 07 '15 14:06

Shaiful Islam


People also ask

How can I increase my session timeout in cakephp 3?

The cookie timeout is controlled by the session. cookie_lifetime ini value and can be configured using: Configure::write('Session', [ 'defaults' => 'php', 'ini' => [ // Invalidate the cookie after 30 minutes without visiting // any page on the site.

How to set session expiry time in PHP?

The timeout limit of the session can be set by setting the value of two directives in the php. ini file or using the ini_set() function in the PHP script. The directives are given below. It is used to set the time limit in seconds to store the session information in the server for a long time.

Is it possible to set a time expire page in PHP?

Session timeout can be customized, to make the user's page inactive after a fixed time. Starting session: The PHP, session_start() function is used to start a session in the web page.

How to destroy session in CakePHP?

To destroy a session, use the destroy() method: $session->destroy(); Destroying a session will remove all serverside data in the session, but will not remove the session cookie.


1 Answers

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
));
like image 134
Deyson Avatar answered Oct 16 '22 08:10

Deyson