Session check if expired by sessionid

Hi,

In frontend, I have model which is related /belongsTo/ to session. I am using sessionid to load model when needed. What I want to achieve is once a day check if old sessions are expired and if so then amend model attribute.
I found Illuminate\Session\Store class, but has no method like this. At least I need to find when was session created so I can calculate if expired.

Is it possible to achieve ?

Thank you

Hi @zemiak5 ,

I have model which is related /belongsTo/ to session.

What is the model class name for the “session”? It should be defined in the relationship.

1 Like

It’s not exactly relationship, my bad.
My model has sessionid saved in column and in event cms.page.init I load model using actual sessionid. It’s ,like, belongsTo, but it’s not defined like belongsTo.
I can use model’s created_at, but it’s not created when session is created so it won’t be accurate. I need to delete some personal details from model after session expired and keep not personal, to comply with GDPR.
Thanks anyway.

Hi @zemiak5,

Ah, I understand now.

If you’re using the default file-based session storage, you could try using \Session::getId(), retrieve the session file from storage/framework, and check the created_at timestamp.

That said, this might not be the most optimal approach.

1 Like