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

fahadkhan1740's avatar

How to delete a session data after a period of time? (OTP)

I am making a mobile number verification using OTP module. I want to associate the OTP with the mobile number for 3 mins only and want to forget the key beyond 3 mins. How can I do so?

I am using the following snippet.

Session::put(['otp' => $otp, 'mobile' => $number]);

0 likes
3 replies
burlresearch's avatar

You could set the global: SESSION_LIFETIME

vi .env

SESSION_LIFETIME=3
Snapey's avatar
Snapey
Best Answer
Level 122

You cannot expire it (nothing is running to check if it has expired)

You can only save what time it was created and then realise that it was too long ago when you come to check it.

1 like

Please or to participate in this conversation.