Skip to content
Permalink
Browse files

Fixes SessionComponentTest::testSessionValid. Refactored _hasSession …

…and other erros on php 7

init would always set CakeSession::$_userAgent.
  • Loading branch information...
phpnut committed Dec 28, 2015
1 parent 027e32c commit a59ea1371239c6d2a31e5be01d06b8d0c12d4d85
Showing with 8 additions and 6 deletions.
  1. +8 −6 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');
}
/**

0 comments on commit a59ea13

Please sign in to comment.
You can’t perform that action at this time.