Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

shinybelly5's avatar

Session ID changes on refresh (Laravel 5.4 + AngularJS 1.6)

Hi Everyone,

Appreciate your time to read through this, Laravel's session ID changes whenever I hit reload on Chrome, however it remains the same if I navigate around the pages (including pages with $http.get requests to the backend). I also realized that the session ID does NOT change when i hit refresh on a static page with no AngularJS $http.get calls to the backend.

So I dug further into the request/response headers, it appeared that the laravel-session cookie is being updated correctly in the next request based on the previous response, up until I call $http.get with AngularJS, chrome's refresh does not pick up the previous laravel-session cookie value returned from $http.get's response. What should I do to fix this, so that the page refreshes + $http requests do not mess up Laravel's session?

Any advice/insights will be very much appreciated!

I have Laravel 5.4 as the API backend and AngularJS frontend, routing is handled by AngularJS. The behaviour is observed in both Chrome and Firefox in Ubuntu.

Cheers, Ed

0 likes
2 replies
jlrdw's avatar
jlrdw
Best Answer
Level 75

I think it's because of encrypted cookies. I forget where the setting is, but there's a line you can comment out.

2 likes
shinybelly5's avatar

Awesome, @jirdw you are such a saviour! For the rest that stumbled into the issue, under App\Http\Middleware\EncryptCookies, add the cookie name (indicated in session.php) to except array e.g.

protected $except = ['laravel_session'];

1 like

Please or to participate in this conversation.