Skip to content

Commit

Permalink
recreate earlier
Browse files Browse the repository at this point in the history
  • Loading branch information
juliangut committed Sep 16, 2016
1 parent d949bef commit 55520ad
Showing 1 changed file with 5 additions and 17 deletions.
22 changes: 5 additions & 17 deletions src/SessionWare.php
Expand Up @@ -137,13 +137,13 @@ protected function startSession(ServerRequestInterface $request)
// @codeCoverageIgnoreEnd
}

$this->manageSessionTimeout();

$this->populateSession($this->initialSessionParams);

if (strlen(session_id()) !== static::SESSION_ID_LENGTH) {
$this->recreateSession();
}

$this->manageSessionTimeout();

$this->populateSession($this->initialSessionParams);
}

/**
Expand Down Expand Up @@ -333,13 +333,7 @@ protected function manageSessionTimeout()
if (array_key_exists($this->sessionTimeoutKey, $_SESSION) && $_SESSION[$this->sessionTimeoutKey] < time()) {
$this->emit(Event::named('pre.session_timeout'), session_id());

$_SESSION = [];
session_unset();
session_destroy();

session_id(static::generateSessionId());

session_start();
$this->recreateSession();

$this->emit(Event::named('post.session_timeout'), session_id());
}
Expand All @@ -352,19 +346,13 @@ protected function manageSessionTimeout()
*/
protected function recreateSession()
{
$sessionParams = $_SESSION;

$_SESSION = [];
session_unset();
session_destroy();

session_id(SessionWare::generateSessionId());

session_start();

foreach ($sessionParams as $param => $value) {
$_SESSION[$param] = $value;
}
}

/**
Expand Down

0 comments on commit 55520ad

Please sign in to comment.