diff --git a/app/Config/core.php b/app/Config/core.php index e8dc9afda..da5555a34 100644 --- a/app/Config/core.php +++ b/app/Config/core.php @@ -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 diff --git a/lib/Cake/Model/Datasource/CakeSession.php b/lib/Cake/Model/Datasource/CakeSession.php index a692ed74c..8e9429b53 100644 --- a/lib/Cake/Model/Datasource/CakeSession.php +++ b/lib/Cake/Model/Datasource/CakeSession.php @@ -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); + } } /**