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

phpMick's avatar
Level 15

Session gone but still logged in

Here is a funny one.

I store my users permissions in the session (they come from another db and I only want to hit it once).

If they haven't used the system for a while (days), it looks like they are still logged in (Chrome), but the session is gone.

When they try and browse to a page, my application errors out because they don't have any permissions.

I was thinking I could just check the session and send them to auth/logout, this would make them log in again and populate the session.

Mick

0 likes
6 replies
phpMick's avatar
Level 15

I think this is because I am remembering users.

SaeedPrez's avatar
Level 50

Create a middleware, if user is logged in and does not have the permissions, hit the other database and get the permissions. This way you can offer the remember me functionality to your users instead of forcing them to re-log.

phpMick's avatar
Level 15

That sounds good. My biggest problem is that i can't recreate, so will be hard to test. Any idea how I can reproduce?

Shoved this in and I get the same error:

$request->session()->flush();

SaeedPrez's avatar

Are you talking about testing or what do you mean recreate/reproduce?

session()->forget('key');
session()->flush();

Remember me is set in cookies, so you can always delete the session..

phpMick's avatar
Level 15

Sorted this now @SaeedPrez.

I have middleware which sets the permissions session array, if it is missing.

Cheers,

Mick

1 like

Please or to participate in this conversation.