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
Setting Value of a HTML Form Textarea
PHP Objects VS Arrays -- Performance Comparison While Iterating
PHP Replacing Special Characters Like à->A, è->E
PHP - Get Base64 Img String Decode and Save as Jpg (Resulting Empty Image )
Uncaught Reflectionexception: Class Log Does Not Exist Laravel 5.2
How Get Value for Unchecked Checkbox in Checkbox Elements When Form Posted
How to Set .Env Values in Laravel Programmatically on the Fly
PHP Function Ssh2_Connect Is Not Working
Apache Rewrite - Get Original Url in PHP
Laravel Multiple Pagination in One Page
Regex Pattern to Get the Youtube Video Id from Any Youtube Url
Object of Class Datetime Could Not Be Converted to String
Convert Flat Array to the Multi-Dimensional
Find Out Which Class Called a Method in Another Class
Create a Comma-Separated String from a Single Column of an Array of Objects