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.
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.
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.
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.
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.
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
));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With