简体   繁体   English

Laravel随机验证CSRF令牌

[英]Laravel Random Verify CSRF Token

I currently have a web application in the process of being built in Laravel 5.3. 我目前正在使用Laravel 5.3构建一个Web应用程序。

I have it running locally on my MacBook Pro using Laravel Valet with a SQL Server. 我使用带有SQL Server的Laravel Valet在MacBook Pro上本地运行。 All intended functionality works. 所有预期的功能均有效。

I then uploaded it up to my Ubuntu web server on DigitalOcean and have had it up there ever since I started this project ( 8 months ago ) without any issues. 然后,我将其上传到DigitalOcean上的Ubuntu Web服务器,并且自从启动此项目(8个月前)以来就一直将其存储在那里。

For a specific form POST Request I am receiving a Token Mismatch Error: 对于特定形式的POST请求,我收到令牌不匹配错误:

TokenMismatchException in VerifyCsrfToken.php line 68

The user is already logged in and other POST Requests on the application work. 用户已经登录,并且该应用程序上的其他POST请求正常运行。 The form has the correct CSRF Token inside of the form and has the token stored in the head of the page under a meta tag ( ). 表单在表单内部具有正确的CSRF令牌,并且令牌存储在页面顶部的meta标签()下。

I am not having this issue locally and they both have the same Database Schema and Content. 我在本地没有这个问题,他们都有相同的数据库架构和内容。

I fail to understand why this issue would only happen on the web server. 我不明白为什么这个问题只会在Web服务器上发生。

Any help is much appreciated. 任何帮助深表感谢。

Based on my assumption: Make sure that you are added $this->middleware('auth'); 根据我的假设:确保已添加$this->middleware('auth'); into the constructor of your controller which handle that post request. 到处理该发布请求的控制器的构造函数中。

Also try with use below one of the csrf token field option: 还可以尝试使用以下csrf令牌字段选项之一:

<input type="hidden" name="_token" value="{{ csrf_token() }}">

Or: 要么:

{{ csrf_field() }}

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

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