简体   繁体   中英

How to solve TokenMismatchException in VerifyCsrfToken.php line 67

When I have submit form then I am getting a Error. You can view Error Related Token Mismatch Exception.

How to solve

TokenMismatchException in VerifyCsrfToken.php line 67: error

I have already added token Variable.

<input name="_token" value="dZfqvG7m1G0TGtXtWkDoWFXs5wqIwH86mMzCKfTy" type="hidden">

Is there any other solution for that

Try checking the session.php file in the config folder. Maybe the path of your laravel installation is incorrect.

Also try to check if your application has write access to the session directory.

chmod 777 ./storage/framework/sessions

The CSRF token works by flashing the value to your session, then comparing the value with what was submitted with your form on the next request. If your sessions are not being set then this will always fail.

note: Just clearing the browser cookies works as well sometimes ;)

If you're using AJAX POST dont forget to add the following

in your head section:

< meta name="csrf-token" content="{{ csrf_token() }}" />

in your javascript section:

$.ajaxSetup({
     headers: {
       'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
     }
});

This is how I solved the issue.

I am using Session_driver=file (.env file)

Clear session data: Delete all files in storage/frameworks/sessions/

Artisan clear cache: php artisan cache:clear

Restart apache in ubuntu: Sudo service apache2 restart

Clear browser cache in chrome or another browser you are using

Edit this file:

 vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php

add 'POST' to

  protected function isReading($request)
    {
        return in_array($request->method(), ['HEAD', 'GET', 'OPTIONS', 'POST']);
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM