Skip to content

Commit

Permalink
Adding fix when a invalid session is destroyed in CakeSession::_check…
Browse files Browse the repository at this point in the history
…Valid(); and session data wrote after the session is destroyed no longer being available because the session data was wrote using the old session id

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7976 3807eeeb-6ff5-0310-8944-8be069107fe0
  • Loading branch information
phpnut committed Jan 14, 2009
1 parent 7b12272 commit a6250ad
Showing 1 changed file with 9 additions and 19 deletions.
28 changes: 9 additions & 19 deletions cake/libs/session.php
Expand Up @@ -398,21 +398,11 @@ function write($name, $value) {
* @access public * @access public
*/ */
function destroy() { function destroy() {
$sessionpath = session_save_path();
if (empty($sessionpath)) {
$sessionpath = "/tmp";
}

if (isset($_COOKIE[session_name()])) {
setcookie(Configure::read('Session.cookie'), '', time() - 42000, $this->path);
}

$_SESSION = array(); $_SESSION = array();
$file = $sessionpath . DS . "sess_" . session_id();
@session_destroy();
@unlink ($file);
$this->__construct($this->path); $this->__construct($this->path);
$this->start();
$this->renew(); $this->renew();
$this->_checkValid();
} }
/** /**
* Helper method to initialize a session, based on Cake core settings. * Helper method to initialize a session, based on Cake core settings.
Expand Down Expand Up @@ -447,7 +437,7 @@ function __initSession() {


switch (Configure::read('Session.save')) { switch (Configure::read('Session.save')) {
case 'cake': case 'cake':
if (!isset($_SESSION)) { if (empty($_SESSION)) {
if ($iniSet) { if ($iniSet) {
ini_set('session.use_trans_sid', 0); ini_set('session.use_trans_sid', 0);
ini_set('url_rewriter.tags', ''); ini_set('url_rewriter.tags', '');
Expand All @@ -462,7 +452,7 @@ function __initSession() {
} }
break; break;
case 'database': case 'database':
if (!isset($_SESSION)) { if (empty($_SESSION)) {
if (Configure::read('Session.table') === null) { if (Configure::read('Session.table') === null) {
trigger_error(__("You must set the all Configure::write('Session.*') in core.php to use database storage"), E_USER_WARNING); trigger_error(__("You must set the all Configure::write('Session.*') in core.php to use database storage"), E_USER_WARNING);
exit(); exit();
Expand All @@ -489,7 +479,7 @@ function __initSession() {
array('CakeSession', '__gc')); array('CakeSession', '__gc'));
break; break;
case 'php': case 'php':
if (!isset($_SESSION)) { if (empty($_SESSION)) {
if ($iniSet) { if ($iniSet) {
ini_set('session.use_trans_sid', 0); ini_set('session.use_trans_sid', 0);
ini_set('session.name', Configure::read('Session.cookie')); ini_set('session.name', Configure::read('Session.cookie'));
Expand All @@ -499,7 +489,7 @@ function __initSession() {
} }
break; break;
case 'cache': case 'cache':
if (!isset($_SESSION)) { if (empty($_SESSION)) {
if (!class_exists('Cache')) { if (!class_exists('Cache')) {
uses('Cache'); uses('Cache');
} }
Expand All @@ -521,7 +511,7 @@ function __initSession() {
array('CakeSession', '__gc')); array('CakeSession', '__gc'));
break; break;
default: default:
if (!isset($_SESSION)) { if (empty($_SESSION)) {
$config = CONFIGS . Configure::read('Session.save') . '.php'; $config = CONFIGS . Configure::read('Session.save') . '.php';


if (is_file($config)) { if (is_file($config)) {
Expand All @@ -538,7 +528,7 @@ function __initSession() {
*/ */
function __startSession() { function __startSession() {
if (headers_sent()) { if (headers_sent()) {
if (!isset($_SESSION)) { if (empty($_SESSION)) {
$_SESSION = array(); $_SESSION = array();
} }
return false; return false;
Expand Down Expand Up @@ -603,7 +593,7 @@ function __regenerateId() {
if (empty($sessionpath)) { if (empty($sessionpath)) {
$sessionpath = "/tmp"; $sessionpath = "/tmp";
} }
if (isset($_COOKIE[session_name()])) { if (session_id() != "" || isset($_COOKIE[session_name()])) {
setcookie(Configure::read('Session.cookie'), '', time() - 42000, $this->path); setcookie(Configure::read('Session.cookie'), '', time() - 42000, $this->path);
} }
session_regenerate_id(true); session_regenerate_id(true);
Expand Down

0 comments on commit a6250ad

Please sign in to comment.