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

CooL's avatar
Level 2

Session expired

Hello all. I have simple question, but i can't solve it. I have session for example 1 minute and after 1 minute expire and i'm manually refreshing the page - i want laravel to redirect me to the login page.

In other version of laravel i just wrote TokenMissmatchException and it was fine for me:

public function render($request, Exception $exception)
    {
        if ($exception instanceof TokenMismatchException) {

            return redirect('/login')->with('message', 'Sorry, your session seems to have expired. Please login again.');

        }
        return parent::render($request, $exception);
    }

but in latest 5.4 version the same thing is not working, it's not even throws this exception. Can anyone assist ?

0 likes
6 replies
jlrdw's avatar

Have you checked file permissions, and your config files for session expire time?

CooL's avatar
Level 2

i put 1 minute manually to check:

    'lifetime' => 1,

And yes, i checked the permissions and even change it to 777 for testing purpose. I already did this thing in my another project and it's working fine, but here i don't know why, but it don't throw this exception, it don't comes inside the function.

Snapey's avatar

then either your session is not actually expired or the page you are refreshing does not require authentication.

token mismatch would only kick in when posting a form and not just refreshing the page

CooL's avatar
Level 2

I don't need to redirect when i'm submitting the form. I only need to redirect to login page when i'm manually refreshing the page and if session expired - redirect to login page. session is 100 % expired. Screen before session expired: http://joxi.ru/zAN4Zeyc3OwBm9

Screen after: http://joxi.ru/VrwnaY3CydgzAX

Even screen is changin when session expired.

Snapey's avatar

what about the remember me token?

CooL's avatar
Level 2

no remember me token. I'm login in without it.

Please or to participate in this conversation.