Skip to content

Commit

Permalink
Check status before session, fixes #32
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanjhv committed Jul 21, 2018
1 parent 58beaeb commit 920c539
Showing 1 changed file with 16 additions and 19 deletions.
35 changes: 16 additions & 19 deletions src/Slim/Middleware/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ public function __invoke(Request $request, Response $response, callable $next)
*/
protected function startSession()
{
$inactive = session_status() === PHP_SESSION_NONE;
if (!$inactive) return;

$settings = $this->settings;
$name = $settings['name'];

Expand All @@ -94,22 +97,18 @@ protected function startSession()
$settings['httponly']
);

$inactive = session_status() === PHP_SESSION_NONE;

if ($inactive) {
// Refresh session cookie when "inactive",
// else PHP won't know we want this to refresh
if ($settings['autorefresh'] && isset($_COOKIE[$name])) {
setcookie(
$name,
$_COOKIE[$name],
time() + $settings['lifetime'],
$settings['path'],
$settings['domain'],
$settings['secure'],
$settings['httponly']
);
}
// Refresh session cookie when "inactive",
// else PHP won't know we want this to refresh
if ($settings['autorefresh'] && isset($_COOKIE[$name])) {
setcookie(
$name,
$_COOKIE[$name],
time() + $settings['lifetime'],
$settings['path'],
$settings['domain'],
$settings['secure'],
$settings['httponly']
);
}

session_name($name);
Expand All @@ -123,9 +122,7 @@ protected function startSession()
}

session_cache_limiter(false);
if ($inactive) {
session_start();
}
session_start();
}

protected function iniSet($settings)
Expand Down

0 comments on commit 920c539

Please sign in to comment.