You’ll hit this when submitting a login, contact or order form, or with AJAX POST requests. Laravel protects every state-changing request with a CSRF token tied to the user’s session; if the token is missing or doesn’t match, it rejects the request with 419 | Page Expired.
What the error means
When a page with a form loads, Laravel puts a random token in a hidden _token field and stores the same token in the user’s session. On submit, it compares the two. The error doesn’t mean your code is broken: it means the link between the page and the session broke somewhere.
For visitors: refresh the page, submit the form again, and make sure your browser accepts cookies for the site.
Common causes
- The form has no
@csrf. - An AJAX request doesn’t send the
X-CSRF-TOKENheader. - The session expired because the page was open longer than
SESSION_LIFETIME. - The session cookie isn’t saved: wrong
SESSION_DOMAIN,SESSION_SECURE_COOKIE=trueon a site served over HTTP, or switching betweenwwwand non-www. storage/framework/sessionsisn’t writable withSESSION_DRIVER=file, or thesessionstable is missing withSESSION_DRIVER=database.- The form page is cached by a page cache or CDN, so every visitor gets one visitor’s token.
APP_KEYwas changed, invalidating existing session cookies.
How to fix it
- Add the token to every POST form:
<form method="POST" action="{{ route('contact.send') }}">
@csrf
<input type="email" name="email">
<button type="submit">Send</button>
</form>
- Send the token with AJAX: put it in the page head, then send it as a header:
<meta name="csrf-token" content="{{ csrf_token() }}">
fetch('/cart', {
method: 'POST',
headers: {
'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"]').content,
'Content-Type': 'application/json'
},
body: JSON.stringify({ product_id: 5 })
});
Laravel’s preconfigured Axios sends the token automatically from the XSRF-TOKEN cookie.
3. Check the session settings in .env:
APP_URL=https://example.com
SESSION_DRIVER=file
SESSION_LIFETIME=120
SESSION_DOMAIN=null
SESSION_SECURE_COOKIE=true
Only use SESSION_SECURE_COOKIE=true when the whole site runs on HTTPS, and redirect everyone to a single version of the domain.
4. Clear the config cache after editing .env, because Laravel ignores .env while configuration is cached:
php artisan config:clear
- Check where sessions are stored: with
file,storage/framework/sessionsmust be writable; see storage permission errors. Withdatabase, runphp artisan migrate: the default migrations in Laravel 11 and later create thesessionstable. - Don’t cache form pages: exclude login, checkout and contact pages from any cache rules in
.htaccessor a CDN. - Exclude only webhook routes, in
bootstrap/app.php(Laravel 11 and later):
->withMiddleware(function (Middleware $middleware) {
$middleware->validateCsrfTokens(except: [
'payments/callback',
]);
})
Prevention
- Use
@csrfin every form, plus@method('PUT')on forms that update data. - Set
APP_URLand theSESSION_*values in the server’s.envinstead of copying your local file. - Avoid changing
APP_KEYon a running site unless you have to.
On ArabyHost
A free SSL certificate is issued automatically, so you can run the whole site on HTTPS with SESSION_SECURE_COOKIE=true. Point the domain’s document root to the public folder of your Laravel project. AI/Developer plans include SSH for artisan commands; on other plans, edit .env in File Manager and delete bootstrap/cache/config.php instead of running config:clear. The Araby AI assistant reads the error log, and there’s more in Laravel hosting.
FAQ
Is 419 an official HTTP status code?
No, it isn't part of the standard HTTP codes. Laravel uses it specifically when CSRF validation fails, i.e. on a TokenMismatchException.
Why does it happen after leaving the page open for a long time?
The session expired according to SESSION_LIFETIME, which defaults to 120 minutes, so the token in the form is no longer valid. Refreshing and resubmitting is enough; raise the lifetime if your forms take long to fill in.
How do I exclude a payment gateway webhook from CSRF checks?
In Laravel 11 and later, use validateCsrfTokens(except: [...]) in bootstrap/app.php; in older versions, add the path to the $except array in VerifyCsrfToken. Exclude only the webhook route, and verify the gateway's signature inside it.