VerifyCsrfToken.php 第 67 行中的 TokenMismatchException [英] TokenMismatchException in VerifyCsrfToken.php Line 67
问题描述
我知道这是 Laravel 中表单之类的已知错误.但是我在 Laravel 5.2 中面临基本身份验证的问题.
I know that this is a known error with things like forms in Laravel. But I am facing an issue with basic authentication in Laravel 5.2.
我使用 Laravel 创建了身份验证;
I created the auth using Laravel;
php artisan make:auth
现在我在我的服务器和我的本地都有相同的代码副本.在我的本地,我没有任何问题.然而,在我的服务器上,当我尝试注册用户时,我收到错误消息,说 TokenMismatchException in VerifyCsrfToken.php Line 67
Now I have the same copy of code on my server and my local. On my local I am getting no issue whatsoever. However on my server, when I try to register a user I get the error saying TokenMismatchException in VerifyCsrfToken.php Line 67
我的本地和服务器环境都同步,但我在注册时不断收到错误消息.有关如何解决此问题的任何帮助?
Both my local and server environments are in sync, yet I keep getting the error on registration. Any help on how I can fix this?
推荐答案
我假设您在控制器的构造函数中添加了 $this->middleware('auth');
以获得身份验证工作.在您的登录/注册表单中,如果您使用 {!!Form::someElement !!}
,在顶部添加以下行:
I'm assuming you added $this->middleware('auth');
inside the constructor of your controller to get the authentication working. In your login/register forms, if you are using {!! Form::someElement !!}
, add the following line at the top as well:
{!! csrf_field() !!}
或者,如果您在表单中使用输入标签,只需在 <form>
标签后添加以下行:
Or if you are using input tags inside your forms, just add the following line after <form>
tag:
<input type="hidden" name="_token" value="{{ csrf_token() }}">
希望这会有所帮助.
这篇关于VerifyCsrfToken.php 第 67 行中的 TokenMismatchException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!