From bc1678cf2af1246e02739d352e4d3bf84a452f36 Mon Sep 17 00:00:00 2001 From: Mischa ter Smitten Date: Thu, 23 Nov 2017 10:02:38 +0100 Subject: [PATCH 1/5] Add option to make `_validAgentAndTime` 3.x compatible --- lib/Cake/Model/Datasource/CakeSession.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lib/Cake/Model/Datasource/CakeSession.php b/lib/Cake/Model/Datasource/CakeSession.php index a692ed74c..b9917721e 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['use_forwards_compatible_timeout']) && $sessionConfig['use_forwards_compatible_timeout']) { + static::$_useForwardsCompatibleTimeout = true; + } + if (!isset($sessionConfig['ini']['session.cookie_lifetime'])) { $sessionConfig['ini']['session.cookie_lifetime'] = $sessionConfig['cookieTimeout'] * 60; } @@ -580,6 +594,9 @@ class CakeSession { } Configure::write('Session', $sessionConfig); static::$sessionTime = static::$time + ($sessionConfig['timeout'] * 60); + if (static::$_useForwardsCompatibleTimeout) { + static::$sessionTime = static::$time; + } } /** From 4faac8e09a259912bf6dba299088d79dce566e3b Mon Sep 17 00:00:00 2001 From: Mischa ter Smitten Date: Thu, 23 Nov 2017 10:06:14 +0100 Subject: [PATCH 2/5] Improved readability --- lib/Cake/Model/Datasource/CakeSession.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/Cake/Model/Datasource/CakeSession.php b/lib/Cake/Model/Datasource/CakeSession.php index b9917721e..3a01f819f 100644 --- a/lib/Cake/Model/Datasource/CakeSession.php +++ b/lib/Cake/Model/Datasource/CakeSession.php @@ -593,9 +593,9 @@ class CakeSession { ); } Configure::write('Session', $sessionConfig); - static::$sessionTime = static::$time + ($sessionConfig['timeout'] * 60); - if (static::$_useForwardsCompatibleTimeout) { - static::$sessionTime = static::$time; + static::$sessionTime = static::$time; + if (!static::$_useForwardsCompatibleTimeout) { + static::$sessionTime += ($sessionConfig['timeout'] * 60); } } From 05954ff405042a98dc09a1701a267da09a8e01c1 Mon Sep 17 00:00:00 2001 From: Mischa ter Smitten Date: Thu, 23 Nov 2017 10:09:25 +0100 Subject: [PATCH 3/5] Consistency changes --- lib/Cake/Model/Datasource/CakeSession.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cake/Model/Datasource/CakeSession.php b/lib/Cake/Model/Datasource/CakeSession.php index 3a01f819f..28e25a79b 100644 --- a/lib/Cake/Model/Datasource/CakeSession.php +++ b/lib/Cake/Model/Datasource/CakeSession.php @@ -537,7 +537,7 @@ class CakeSession { if (isset($sessionConfig['timeout']) && !isset($sessionConfig['cookieTimeout'])) { $sessionConfig['cookieTimeout'] = $sessionConfig['timeout']; } - if (isset($sessionConfig['use_forwards_compatible_timeout']) && $sessionConfig['use_forwards_compatible_timeout']) { + if (isset($sessionConfig['useForwardsCompatibleTimeout']) && $sessionConfig['useForwardsCompatibleTimeout']) { static::$_useForwardsCompatibleTimeout = true; } From c437efd2a53cb1ec49e0237c8216aa52c6c0afa4 Mon Sep 17 00:00:00 2001 From: Mischa ter Smitten Date: Thu, 23 Nov 2017 10:13:42 +0100 Subject: [PATCH 4/5] Improved documentation --- app/Config/core.php | 1 + 1 file changed, 1 insertion(+) 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 From d7b9e55e98b478f49fda74358db3b4433f98d29d Mon Sep 17 00:00:00 2001 From: Mischa ter Smitten Date: Thu, 23 Nov 2017 14:12:13 +0100 Subject: [PATCH 5/5] Fix indent --- lib/Cake/Model/Datasource/CakeSession.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cake/Model/Datasource/CakeSession.php b/lib/Cake/Model/Datasource/CakeSession.php index 28e25a79b..8e9429b53 100644 --- a/lib/Cake/Model/Datasource/CakeSession.php +++ b/lib/Cake/Model/Datasource/CakeSession.php @@ -538,7 +538,7 @@ class CakeSession { $sessionConfig['cookieTimeout'] = $sessionConfig['timeout']; } if (isset($sessionConfig['useForwardsCompatibleTimeout']) && $sessionConfig['useForwardsCompatibleTimeout']) { - static::$_useForwardsCompatibleTimeout = true; + static::$_useForwardsCompatibleTimeout = true; } if (!isset($sessionConfig['ini']['session.cookie_lifetime'])) {