简体   繁体   English

如何解决VerifyCsrfToken.php第67行中的TokenMismatchException

[英]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 VerifyCsrfToken.php 第 67 行中的 TokenMismatchException:错误

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.尝试检查 config 文件夹中的session.php文件。 Maybe the path of your laravel installation is incorrect.可能你的 Laravel 安装路径不正确。

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. CSRF 令牌的工作原理是将值闪烁到您的会话中,然后将该值与在下一个请求中随表单提交的值进行比较。 If your sessions are not being set then this will always fail.如果您的会话未设置,那么这将始终失败。

note: Just clearing the browser cookies works as well sometimes ;)注意:有时只需清除浏览器 cookie 也能正常工作 ;)

If you're using AJAX POST dont forget to add the following如果您使用 AJAX POST,请不要忘记添加以下内容

in your head section:在你的头部部分:

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

in your javascript section:在您的 javascript 部分:

$.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)我正在使用 Session_driver=file (.env 文件)

Clear session data: Delete all files in storage/frameworks/sessions/清除会话数据:删除 storage/frameworks/sessions/ 中的所有文件

Artisan clear cache: php artisan cache:clear工匠清除缓存:php工匠缓存:清除

Restart apache in ubuntu: Sudo service apache2 restart在 ubuntu 中重启 apache:Sudo service apache2 restart

Clear browser cache in chrome or another browser you are using清除 chrome 或您正在使用的其他浏览器中的浏览器缓存

Edit this file:编辑此文件:

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

add 'POST' to将“POST”添加到

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Laravel 5-VerifyCsrfToken.php 67行中的TokenMismatchException - Laravel 5 - TokenMismatchException in VerifyCsrfToken.php line 67 VerifyCsrfToken.php 67行中的错误TokenMismatchException: - Error TokenMismatchException in VerifyCsrfToken.php line 67: 如何在Laravel 5.2中的VerifyCsrfToken.php 67行中修复TokenMismatchException - how to fix TokenMismatchException in VerifyCsrfToken.php line 67 in laravel 5.2 PHP Laravel:VerifyCsrfToken.php 67行中的TokenMismatchException - PHP Laravel : TokenMismatchException in VerifyCsrfToken.php line 67 错误:laravel 5.2中VerifyCsrfToken.php第67行中的TokenMismatchException - Error: TokenMismatchException in VerifyCsrfToken.php line 67 in laravel 5.2 上传视频时,VerifyCsrfToken.php 67行中的TokenMismatchException - TokenMismatchException in VerifyCsrfToken.php line 67 when uploading video 使用Route :: post()在VerifyCsrfToken.php第67行中的TokenMismatchException - TokenMismatchException in VerifyCsrfToken.php line 67 using Route::post() 使用ajax在laravel上的VerifyCsrfToken.php第67行中的TokenMismatchException - TokenMismatchException in VerifyCsrfToken.php line 67 on laravel using ajax Laravel 5.2-VerifyCsrfToken.php 67行中的TokenMismatchException: - Laravel 5.2 - TokenMismatchException in VerifyCsrfToken.php line 67: VerifyCsrfToken.php 67行中的TokenMismatchException:在Laravel 5.2中 - TokenMismatchException in VerifyCsrfToken.php line 67: in Laravel 5.2
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM