Laravel 5.5 the Page Has Expired Due to Inactivity. Please Refresh and Try Again

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

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'
];

why error laravel 5.5 The page has expired due to inactivity. Please refresh and try again even after {{ csrf_field() }}

You should change lifetime of your session so that CSRF token could stick around longer. It is set up in config/session.php file, by default it's configured as:

'lifetime' => env('SESSION_LIFETIME', 120),

Meaning your session will persist for 120 minutes by default if not set otherwise in your .env file.

The page has expired due to inactivity - Laravel 5.5

If you're coming to this answer directly from a search, make sure you have already added the csrf token to your form with {{ csrf_field() }} like the OP.


If you have your session driver set to file:

May have something to do with the storage_path not being writable. This is where it stores session data regarding tokens if you're using file based sessions. The can be verified with is_writable(config('session.files'))


For the OP, the session driver was set to array. Array is for testing only. Since data is not persisted, it will not be able to compare the token on the next request.

The array driver is used during testing and prevents the data stored
in the session from being persisted.

https://laravel.com/docs/5.5/session#configuration


Check config/session.php

Lastly, an issue I just had, we had a project which has the session domain and secure settings in config/session.php but the development site was not using HTTPS (SSL/TLS). This caused this generic error since sessions.secure was set to true by default.

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

I had figured it out i did it from scratch it was the problem of Auth function
The import Auth before that i did run two commands to clear my cache

php artisan cache:clear

php artisan config:cache

and import Auth

Thank you for the help guys appreciate it

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

With Laravel 5.6 using Blades templates, it's pretty easy.

<form method="POST" action="/profile">
@csrf
...
</form>

It doesn't work, then Refresh the browser cache and now it might work. (When we update our application, a browser may still use old files. If you don’t clear your cache, Old files can access problems when you apply)

For more details open link:- CSRF Protection in Laravel 5.6



Related Topics



Leave a reply



Submit