Skip to content

Commit

Permalink
Fixes SessionComponentTest::testSessionValid. Refactored _hasSession …
Browse files Browse the repository at this point in the history
…and other erros on php 7

init would always set CakeSession::$_userAgent.
  • Loading branch information
phpnut committed Dec 28, 2015
1 parent 027e32c commit a59ea13
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions lib/Cake/Model/Datasource/CakeSession.php
Expand Up @@ -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'));
}

Expand Down Expand Up @@ -202,7 +202,6 @@ public static function start() {

$id = static::id();
static::_startSession();

if (!$id && static::started()) {
static::_checkValid();
}
Expand All @@ -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();
}

/**
Expand Down Expand Up @@ -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()]);
Expand Down Expand Up @@ -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');
}

/**
Expand Down

0 comments on commit a59ea13

Please sign in to comment.