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

miwal's avatar
Level 11

Session key being set even for unlogged visits? (Redis session driver)

I've just been playing about with adding a separate redis instance to store sessions, and found that a key is set as a result even of an unlogged visit.

This conflicts with my understanding of what sessions are supposed to be. Can someone explain? Or point to source which would explain this?

Thank you!

I saw a discussion here which might be about this, but that's for Laravel 4: https://github.com/laravel/framework/issues/726

0 likes
2 replies
Cronix's avatar
Cronix
Best Answer
Level 67

If by "unlogged visit" you mean they weren't logged in (just an anonymous visitor to the site) then it's normal. This is just how php sessions work (including Laravel).

You can use sessions for non-logged in users. For instance, the session is where the csrf token is stored. How would a non-logged in user fill out a form with csrf protection if there wasn't some sort of session? The session also stores the last url that they were on, so you can redirect()->back(), etc.

It does this for all session types, including the file session driver.

1 like
miwal's avatar
Level 11

Thanks @Cronix for another great answer.

So, if I understand correctly, session only needs an extant client (e.g. a browser), not a logged state. A logged user just means to add authentication on top. And even if a user is "anonymous", we can still track the same visitor's visit to several pages on our site.

So I could just go ahead and use Session:: on public pages that did not assume any Auth::.

Cool... I think there's lots I could potentially do with that.

Please or to participate in this conversation.