VerifyCsrfToken.php第46行中的TokenMismatchException

VerifyCsrfToken.php第46行中的TokenMismatchException,php,laravel,laravel-5,Php,Laravel,Laravel 5,我正在尝试使用curlpost方法提交表单。我已将csrf令牌正确设置为表单 <form action="{{URL::route('the-route')}}" method="post"><input name="_token" type="hidden" value="{{csrf_token()}}"> 但是它在VerifyCsrfToken.php第46行中显示了TokenMismatchException。我一直使用共享托管,我在myapp文件夹中

我正在尝试使用curlpost方法提交表单。我已将csrf令牌正确设置为表单

<form  action="{{URL::route('the-route')}}"   method="post"><input name="_token" type="hidden" value="{{csrf_token()}}">

但是它在
VerifyCsrfToken.php第46行中显示了
TokenMismatchException
。我一直使用共享托管,我在
myapp
文件夹中包含了我的larvel 5项目,在
public\u html
文件夹中包含了
laravel public
文件夹

作为一个测试,我也尝试了一些其他帖子建议的评论
App\Http\Middleware\VerifyCsrfToken
,位于
App/Http/kernal.php
看看会发生什么。每次提交表单后,我都会收到一条消息,上面写着重定向到:
/auth/login
/auth/register
,这取决于我来自哪里,但没有成功

I just got it working removing the line:

'Illuminate\Foundation\Http\Middleware\VerifyCsrfToken'

from /app/Http/Resquests/Kernel.php

谢谢@Mahmoud Nassar

我解决了我的问题:

在我的例子中,我从
app/Http/kernal.php
中删除了
'illumb\Foundation\Http\Middleware\VerifyCsrfToken'
,但它不起作用,但这是VerifyCsrfToken.php第46行中
令牌不匹配异常的最佳解决方案

我在一个共享主机中托管了laravel 5,作为一个测试,我还尝试了一些其他帖子建议的注释更改我的文件夹结构在外部
public\u html
中创建一个文件夹,并在该文件夹中添加文件,然后将
public(laravel)
public\u html中的
文件夹
每次提交表单后,我都会收到一条消息,上面写着重定向到:/auth/login或/auth/register,这取决于我来自哪里,但没有成功

I just got it working removing the line:

'Illuminate\Foundation\Http\Middleware\VerifyCsrfToken'

from /app/Http/Resquests/Kernel.php
因此,我删除了所有文件和文件夹,包括我的应用程序和laravel

最后,我在
public\u html
中创建了laravel 5,并在.htaccess中添加了以下代码(如果不存在,则在laravel根目录上创建一个.htaccess)


此.htaccess可帮助您从url中删除
public
,我找到了最适合我的解决方案。您需要做的是:

转到->应用程序->异常->处理程序.php

并在渲染方法中复制并粘贴此选项:

public function render($request, Exception $e)
{
if ($e instanceof TokenMismatchException) {
    Auth::logout();
    return redirect('login')->withErrors('Sorry, your session has expired.     Please login again.');
  }

return parent::render($request, $e);
}

这将为您处理令牌不匹配异常,并在页面上显示友好消息:)。希望它能帮助任何人

嘿,你能通过使用调试器或使用dd()转储变量来验证你的令牌是否与
tokensMatch($request)
中的
tokensMatch($request)
相匹配吗?这不是好的做法,最好找到问题的根源,然后删除csrf保护。