Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Commit

Permalink
ZF2-52: ::regenerateId() fails and ::rememberMe() clears session stor…
Browse files Browse the repository at this point in the history
  • Loading branch information
Thinkscape committed Aug 22, 2011
Showing 1 changed file with 13 additions and 18 deletions.
31 changes: 13 additions & 18 deletions src/SessionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,16 @@ public function sessionExists()
/**
* Start session
*
* if No sesion currently exists, attempt to start it. Calls
* {@link isValid()} once session_start() is called, and raises an
* if No sesion currently exists, attempt to start it. Calls
* {@link isValid()} once session_start() is called, and raises an
* exception if validation fails.
*
*
* @param bool $preserveStorage If set to true, current session storage will not be overwritten by the
* contents of $_SESSION.
* @return void
* @throws Exception
*/
public function start()
public function start($preserveStorage = false)
{
if ($this->sessionExists()) {
return;
Expand All @@ -107,7 +109,9 @@ public function start()
if ($storage instanceof Storage\SessionStorage
&& $_SESSION !== $storage
) {
$storage->fromArray($_SESSION);
if(!$preserveStorage){
$storage->fromArray($_SESSION);
}
$_SESSION = $storage;
}
}
Expand Down Expand Up @@ -257,9 +261,7 @@ public function regenerateId()
session_regenerate_id();
return $this;
}
$this->destroy();
session_regenerate_id();
$this->start();
return $this;
}

Expand Down Expand Up @@ -384,19 +386,12 @@ protected function _setSessionCookieLifetime($ttl)
return;
}

if ($this->sessionExists()) {
$this->destroy(array('send_expire_cookie' => false));

// Since a cookie was destroyed, we should regenerate the ID
$this->regenerateId();
}

// Now simply set the cookie TTL
// Set new cookie TTL
$config->setCookieLifetime($ttl);

if (!$this->sessionExists()) {
// Restart session if necessary
$this->start();
if ($this->sessionExists()) {
// There is a running session so we'll regenerate id to send a new cookie
$this->regenerateId();
}
}
}

0 comments on commit 145b973

Please sign in to comment.