Skip to content
PHP and Laravel3 min read

Laravel 419 Page Expired: causes and fixes

419 | Page Expired

Short answer

419 Page Expired means Laravel rejected a POST request because the CSRF token was missing or didn't match the session. Common causes are a form without @csrf, an expired session, a session cookie that isn't saved because of domain or HTTPS settings, or a cached page. Add @csrf and check the SESSION_ settings in .env.

ArabyHost teamLast updated: ShareWhatsAppXLinkedIn
Contents
  1. What the error means
  2. Common causes
  3. How to fix it
  4. Prevention
  5. On ArabyHost

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-TOKEN header.
  • The session expired because the page was open longer than SESSION_LIFETIME.
  • The session cookie isn’t saved: wrong SESSION_DOMAIN, SESSION_SECURE_COOKIE=true on a site served over HTTP, or switching between www and non-www.
  • storage/framework/sessions isn’t writable with SESSION_DRIVER=file, or the sessions table is missing with SESSION_DRIVER=database.
  • The form page is cached by a page cache or CDN, so every visitor gets one visitor’s token.
  • APP_KEY was changed, invalidating existing session cookies.

How to fix it

  1. 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>
  1. 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
  1. Check where sessions are stored: with file, storage/framework/sessions must be writable; see storage permission errors. With database, run php artisan migrate: the default migrations in Laravel 11 and later create the sessions table.
  2. Don’t cache form pages: exclude login, checkout and contact pages from any cache rules in .htaccess or a CDN.
  3. Exclude only webhook routes, in bootstrap/app.php (Laravel 11 and later):
->withMiddleware(function (Middleware $middleware) {
    $middleware->validateCsrfTokens(except: [
        'payments/callback',
    ]);
})

Prevention

  • Use @csrf in every form, plus @method('PUT') on forms that update data.
  • Set APP_URL and the SESSION_* values in the server’s .env instead of copying your local file.
  • Avoid changing APP_KEY on 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.

Useful? Share it with someone who needs it:WhatsAppXLinkedIn

Read next

Ready to put your idea online?

Fast, isolated hosting, support that understands you, and an AI assistant that fixes problems with you.