Skip to content

Commit

Permalink
Initial fixes for failing session tests
Browse files Browse the repository at this point in the history
  • Loading branch information
phpnut committed Dec 28, 2015
1 parent 1fd3293 commit 5c3bc44
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions lib/Cake/Model/Datasource/CakeSession.php
Expand Up @@ -218,7 +218,7 @@ public static function start() {
* @return bool True if session has been started.
*/
public static function started() {
return isset($_SESSION) && session_id();
return (isset($_SESSION) && session_id()) || isset($_SESSION) && (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg');
}

/**
Expand Down Expand Up @@ -461,7 +461,14 @@ public static function destroy() {
}

if (static::started()) {
if(session_id() && isset($_SESSION)){
session_write_close();
}
session_start();
session_destroy();
if (isset($_COOKIE[static::_cookieName()])){
unset($_COOKIE[static::_cookieName()]);
}
}

$_SESSION = null;
Expand Down Expand Up @@ -753,7 +760,11 @@ public static function renew() {
if (isset($_COOKIE[session_name()])) {
setcookie(Configure::read('Session.cookie'), '', time() - 42000, static::$path);
}
session_regenerate_id(true);
if (!headers_sent()){
session_write_close();
session_start();
session_regenerate_id(true);
}
}

/**
Expand Down

0 comments on commit 5c3bc44

Please sign in to comment.