Session timeout not working in Cakephp 2 - php

I need to define a very large session time on a cakephp 2 application due to a business need. I defined it on the core.php file as follows:
Configure::write('Session', array(
'defaults' => 'php', //defaults => php
'cookie' => 'cookie',
'timeout' => 4320 // 3 days
));
I made a test and arround two hours of inactivity my session is closed, every time I click a button I get back to the logon screen, how can I effectively control my session time?

Use this It may work.it is working for me
core.php
Configure::write('Session', array(
'defaults' => 'php',
'timeout' => 259200,
'ini' => array(
'session.gc_maxlifetime' => 259200 // 3 day
)
));

Related

Session expires very quickly in cakePHP 2.9

I tried many options in config.php file but no success.
Here the options.
first one:
Configure::write('Session', array(
'defaults' => 'php',
'timeout' => 31556926, // The session will timeout after 30 minutes of inactivity
'cookieTimeout' => 31556926,
'ini' => array(
'session.gc_maxlifetime' => 31556926 // 36 hours
)
));
second one:
Configure::write('Session', array(
'defaults' => 'php',
'Session.timeout' => 36000
));
Please let me know, as session expires in middle of work!
use the following code in your (app/Config/core.php)
Configure::write('Session', array(
'defaults' => 'cake',
'timeout' => 30, // The session will timeout after 30 minutes of inactivity
'cookieTimeout' => 1440, // The session cookie will live for at most 24 hours, this does not effect session timeouts
'checkAgent' => false,
'autoRegenerate' => true, // causes the session expiration time to reset on each page load
));

CakePHP - Increasing session time

I need to increase the session time for logged in users on my project. This is the session info in core.php:
Configure::write('Session', array(
'defaults' => 'php',
'cookieTimeout' => 1440,
'autoRegenerate' => true,
'cookie' => 'SYNAPARTY'
));
This generates a cookie that expires in 24 hours. The problem is the user gets logged out after sometime of inactivity. How can I solve this?
Try changing it to:
Configure::write('Session', array(
'defaults' => 'php',
'cookieTimeout' => 1440,
'timeout' => 1440 //Or whatever amount of minutes you want
'autoRegenerate' => true,
'cookie' => 'SYNAPARTY'
));

Auto logout in yii

How to do auto logout after some minute if the user is idle
I am using yii framework.
I can set logout time under user component in main.php
but the question is how to check the user is idle?
if(isset(Yii::app()->request->cookies['lastpageview']) && (time()-(int)Yii::app()->request->cookies['lastpageview']->value > 3600))
{
//logout
}
else
{
Yii::app()->request->cookies['lastpageview'] = new CHttpCookie('lastpageview', time());
}
where 3600 is the max number or seconds allowed
For Yii 1.xx CWebUser has property authTimeout.
From off documentation:
authTimeout - timeout in seconds after which user is logged out if
inactive.
Set it propety into main config:
...
'components' => array(
....
'user' => array(
'authTimeout' => 60*60*5,
),
....
),
...
You can use CDbHttpSession component to make it work:
'components' => array(
'session' => array(
'class' => 'CDbHttpSession',
'timeout' => 1,
),
),
'user' => [
'identityClass' => 'app\models\User',
//'enableAutoLogin' => true,
'enableSession' => true,
'authTimeout' => 900,
],
its working fine to me!(YII 2.0)
time out session after 15 min if request is come after 15 min then auto redirect to site/login page.

how to access CakePHP session from another PHP script?

I am trying to implement a "Single Sign On (SSO)" between my CakePHP script and my wordpress blog. I researched online for it and found some questions such as
Access cakephp session (auth) from outside cakephp
and
Accessing cakephp session variable from a php script?
To do a quick test I then created a test php file in my webroot directory of my CakePHP with below code
<?php
session_name('NMCORE');
session_start();
print_r($_SESSION);
?>
NMCORE is my session name. It's not the default CAKEPHP. I also confirmed it by putting debug(session_name()); in my controller. But the above code returns a blank array. I'm not sure why it's not working. I need your help to figure it out.
The configuration for my Session in my CakePHP's core.php file is
Configure::write('Session', array(
'defaults' => 'cake',
'cookie' => 'NMCORE',
'timeout' => 43200, //30 days
'autoRegenerate' => true,
'checkAgent' => true
));
Does anybody have an idea on why this is not working?
I figured that out. I'm using 'defaults' => 'cake' in my
Configure::write('Session', array(
'defaults' => 'cake',
'cookie' => 'NMCORE',
'timeout' => 43200, //30 days
'autoRegenerate' => true,
'checkAgent' => true
));
When I changed it to 'php' then it worked.
Configure::write('Session', array(
'defaults' => 'php',
'cookie' => 'NMCORE',
'timeout' => 43200, //30 days
'autoRegenerate' => true,
'checkAgent' => true
));

How to get kohana session data outside kohana application?

I want to get the kohana session data outside the kohana application. I mean to say that i want to get the session data in a static file which is not a kohana page.
I have tried many things and atlast i have found the answer,
In your controller class, get the native session id before kohana session instance and store it. Now close the native session and initiate kohana session by passing the session id as an argument.
session_start();
// Store session id and close the session
$sessionId = session_id();
session_write_close();
// Then we can restore the session by using the session id
// and the Session class from Kohana
Session::Instance(Session::$default, $sessionId);
Now you can access the session inside the kohana application.
session_name('kohana'); //Your session name
print_r($_SESSION);
You can apply configuration settings to each of the session adapters by creating a session config file at APPPATH/config/session.php. The following sample configuration file defines all the settings for each adapter:
[!!] As with cookies, a "lifetime" setting of "0" means that the session will expire when the browser is closed.
return array(
'native' => array(
'name' => 'session_name',
'lifetime' => 43200,
),
'cookie' => array(
'name' => 'cookie_name',
'encrypted' => TRUE,
'lifetime' => 43200,
),
'database' => array(
'name' => 'cookie_name',
'encrypted' => TRUE,
'lifetime' => 43200,
'group' => 'default',
'table' => 'table_name',
'columns' => array(
'session_id' => 'session_id',
'last_active' => 'last_active',
'contents' => 'contents'
),
'gc' => 500,
),
);

Categories