diff --git a/src/Illuminate/Session/Middleware/StartSession.php b/src/Illuminate/Session/Middleware/StartSession.php index d62993a28f75..bf4579be6e98 100644 --- a/src/Illuminate/Session/Middleware/StartSession.php +++ b/src/Illuminate/Session/Middleware/StartSession.php @@ -20,6 +20,12 @@ class StartSession implements MiddlewareContract, TerminableMiddleware { */ protected $manager; + /** + * True if handle method called + * @var bool + */ + protected $sessionHandled = false; + /** * Create a new session middleware. * @@ -40,6 +46,7 @@ public function __construct(SessionManager $manager) */ public function handle($request, Closure $next) { + $this->sessionHandled = true; // If a session driver has been configured, we will need to start the session here // so that the data is ready for an application. Note that the Laravel sessions // do not make use of PHP "native" sessions in any way since they are crappy. @@ -76,7 +83,7 @@ public function handle($request, Closure $next) */ public function terminate($request, $response) { - if ($this->sessionConfigured() && ! $this->usingCookieSessions()) + if ($this->sessionHandled && $this->sessionConfigured() && ! $this->usingCookieSessions()) { $this->manager->driver()->save(); }