Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

laravel 5.5 The page has expired due to inactivity. Please refresh and try again

Tags:

php

laravel

I'm new with Laravel and I have a problem which I don't understand. I have а log form in my project and my method is POST. When I try a request the result is:

'The page has expired due to inactivity. Please refresh and try again.'

But if I change the method to GET, It works fine.

Can someone tell me why is that and how to fix it? because of course I need POST method.

like image 639
Svetlozar Avatar asked Sep 11 '17 06:09

Svetlozar


People also ask

What is Page expired in laravel?

The Session Expired or 419 Page Expired error message in Laravel comes up because somewhere your csrf token verification fails which means the App\Http\Middleware\VerifyCsrfToken::class middleware is already turned on. In the form the @csrf blade directive is already added, which should be fine as well.

What is the meaning of Page expired?

Internet Explorer still gives a "Page Has Expired" warning but goes on to explain the situation further: The page you requested was created using information you submitted in a form. This page is no longer available. As a security precaution, Internet Explorer does not automatically resubmit your information for you.


1 Answers

This problem comes from the CSRF token verification which fails. So either you're not posting one or you're posting an incorrect one.

The reason it works for GET is that for a GET route in Laravel, there is no CSRF token posted.

You can either post a CSRF token in your form by calling:

{{ csrf_field() }} 

Or exclude your route (NOT RECOMMENDED DUE TO SECURITY) in app/Http/Middleware/VerifyCsrfToken.php:

protected $except = [     'your/route' ]; 
like image 64
Erik Baars Avatar answered Oct 06 '22 01:10

Erik Baars