eComEvo
eComEvo

Reputation: 12601

Laravel session ID changes on each request

Every time I reload the page, I get a new value out of session()->getId().

Some have suggested adding the laravel_session to the unencrypted cookie exception, but this does not fix it and is not a viable option anyway.

The issue persists no matter which session storage method I use. File, redis, etc all have the same problem.

This is happening on a fresh install of Laravel 7.

Contents of .env:

SESSION_DRIVER=redis
SESSION_LIFETIME=1440
SESSION_DOMAIN=example.test

What's causing this?

Upvotes: 1

Views: 2652

Answers (1)

user8555937
user8555937

Reputation: 2393

That means:

  1. Session driver is not starting up properly
  2. Client you're using to connect to laravel app server does not accept cookies
  3. Cookies are set up for wrong domain and/or path.

For case 1 make sure StartSession middleware exists in app/Kernel.php at $middlewareGroups -> web

For case 3 check this answer. In case your app relies on a single domain/path, I recommend you to remove SESSION_DOMAIN.


Finally, manually remove all sessions from your session driver, then run php artisan config:cache and try again.

Upvotes: 1

Related Questions