Laravel 5 Auth Post Submit - TokenMismatchException in VerifyCsrfToken.php第46行
刚刚在Laravel 5中发布了一个新应用程序,我在使用开箱即用的身份验证时遇到了一些麻烦...
我一直得到:TokenMismatchException in VerifyCsrfToken.php第46行:在提交登录或注册表单时...
我可以在登录表单页面上看到隐藏表单字段中的令牌代码和当时的会话是相同的...
作为测试,我也尝试过其他一些帖子建议在app/Http/kernal中注释掉//'App\Http\Middleware\VerifyCsrfToken'.php看看会发生什么。每次提交表单后,我都会收到一条消息,内容为重定向到:/auth/login或/auth/register,具体取决于我来自哪里,但没有成功。
奇怪的是,当我第一次安装框架时,这是有效的。从那时起,我所做的就是运行一些迁移并设置一些模型和控制器,并使用一些用户数据为数据库设定种子。
更新:
在VerifyCsrfToken第55行的函数tokenmatch()中进一步研究这个问题.php如果我:
var_dump($request->session()->token());
var_dump($request->input('_token'));
我可以看到这两个令牌是不同的,但在形式上使用:
var_dump(Session::all());
{{{ csrf_token() }}}
它们是相同的。会话令牌在到达 VerifyCsrfToken 第 55 行上的函数 tokensMatch() 之前已经更改了一些方式.php
我的堆栈跟踪如下所示:
in VerifyCsrfToken.php line 46
at VerifyCsrfToken->handle(object(Request), object(Closure)) in VerifyCsrfToken.php line 17
at VerifyCsrfToken->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in ShareErrorsFromSession.php line 55
at ShareErrorsFromSession->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in StartSession.php line 61
at StartSession->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 36
at AddQueuedCookiesToResponse->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in EncryptCookies.php line 40
at EncryptCookies->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in CheckForMaintenanceMode.php line 42
at CheckForMaintenanceMode->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 101
at Pipeline->then(object(Closure)) in Kernel.php line 111
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 84
at Kernel->handle(object(Request)) in index.php line 53