PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, January 1, 2022

[FIXED] How to increase cakephp Auth component session expire time

 January 01, 2022     cakephp, cakephp-3.0, php     No comments   

Issue

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.


Solution

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
));


Answered By - Deyson
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing