"The Page Has Expired Due to Inactivity" - Laravel 5.5

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.

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.

Laravel The page has expired due to inactivity

In your app/Exceptions/Handler.php in render function add the lines:

    if ($e instanceof \Illuminate\Session\TokenMismatchException) {

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

}

before the line :

return parent::render($request, $e);

This should redirect to login on a Token mismatch.

Link with further explanation: https://gist.github.com/jrmadsen67/bd0f9ad0ef1ed6bb594e



Related Topics



Leave a reply



Submit