From a59ea1371239c6d2a31e5be01d06b8d0c12d4d85 Mon Sep 17 00:00:00 2001 From: "Larry E. Masters" Date: Mon, 28 Dec 2015 17:26:35 -0500 Subject: [PATCH] Fixes SessionComponentTest::testSessionValid. Refactored _hasSession and other erros on php 7 init would always set CakeSession::$_userAgent. --- lib/Cake/Model/Datasource/CakeSession.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/Cake/Model/Datasource/CakeSession.php b/lib/Cake/Model/Datasource/CakeSession.php index 054779d6d52..ec5e172cbe7 100644 --- a/lib/Cake/Model/Datasource/CakeSession.php +++ b/lib/Cake/Model/Datasource/CakeSession.php @@ -143,7 +143,7 @@ class CakeSession { public static function init($base = null) { static::$time = time(); - if (env('HTTP_USER_AGENT')) { + if (env('HTTP_USER_AGENT') && !static::$_userAgent) { static::$_userAgent = md5(env('HTTP_USER_AGENT') . Configure::read('Security.salt')); } @@ -202,7 +202,6 @@ public static function start() { $id = static::id(); static::_startSession(); - if (!$id && static::started()) { static::_checkValid(); } @@ -218,7 +217,10 @@ public static function start() { * @return bool True if session has been started. */ public static function started() { - return (isset($_SESSION) && (session_id() || (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg'))); + if (PHP_VERSION >=5.4) { + return isset($_SESSION) && (session_status() === PHP_SESSION_ACTIVE); + } + return isset($_SESSION) && session_id(); } /** @@ -461,10 +463,10 @@ public static function destroy() { } if (static::started()) { - if(session_id() && isset($_SESSION)){ + if (session_id() && static::_hasSession()){ session_write_close(); + session_start(); } - session_start(); session_destroy(); if (isset($_COOKIE[static::_cookieName()])){ unset($_COOKIE[static::_cookieName()]); @@ -591,7 +593,7 @@ protected static function _cookieName() { * @return bool */ protected static function _hasSession() { - return static::started() || isset($_COOKIE[static::_cookieName()]); + return static::started() || isset($_COOKIE[session_name()]) || (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg'); } /**