Merge pull request #11456 from tersmitten/cakephp-2x-3x-sessiontime-inconsistent

Add option to make `_validAgentAndTime` 3.x compatible
This commit is contained in:
Mark Story 2017-11-26 21:54:50 -05:00 committed by GitHub
commit 668e7473b9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 1 deletions

View file

@ -198,6 +198,7 @@
*
* - `Session.cookie` - The name of the cookie to use. Defaults to 'CAKEPHP'
* - `Session.timeout` - The number of minutes you want sessions to live for. This timeout is handled by CakePHP
* - `Session.useForwardsCompatibleTimeout` - Whether or not to make timeout 3.x compatible.
* - `Session.cookieTimeout` - The number of minutes you want session cookies to live for.
* - `Session.checkAgent` - Do you want the user agent to be checked when starting sessions? You might want to set the
* value to false, when dealing with older versions of IE, Chrome Frame or certain web-browsing devices and AJAX

View file

@ -134,6 +134,13 @@ class CakeSession {
*/
protected static $_cookieName = null;
/**
* Whether or not to make `_validAgentAndTime` 3.x compatible.
*
* @var bool
*/
protected static $_useForwardsCompatibleTimeout = false;
/**
* Whether this session is running under a CLI environment
*
@ -360,6 +367,9 @@ class CakeSession {
protected static function _validAgentAndTime() {
$userAgent = static::read('Config.userAgent');
$time = static::read('Config.time');
if (static::$_useForwardsCompatibleTimeout) {
$time += (Configure::read('Session.timeout') * 60);
}
$validAgent = (
Configure::read('Session.checkAgent') === false ||
isset($userAgent) && static::$_userAgent === $userAgent
@ -527,6 +537,10 @@ class CakeSession {
if (isset($sessionConfig['timeout']) && !isset($sessionConfig['cookieTimeout'])) {
$sessionConfig['cookieTimeout'] = $sessionConfig['timeout'];
}
if (isset($sessionConfig['useForwardsCompatibleTimeout']) && $sessionConfig['useForwardsCompatibleTimeout']) {
static::$_useForwardsCompatibleTimeout = true;
}
if (!isset($sessionConfig['ini']['session.cookie_lifetime'])) {
$sessionConfig['ini']['session.cookie_lifetime'] = $sessionConfig['cookieTimeout'] * 60;
}
@ -579,7 +593,10 @@ class CakeSession {
);
}
Configure::write('Session', $sessionConfig);
static::$sessionTime = static::$time + ($sessionConfig['timeout'] * 60);
static::$sessionTime = static::$time;
if (!static::$_useForwardsCompatibleTimeout) {
static::$sessionTime += ($sessionConfig['timeout'] * 60);
}
}
/**