VerifyCsrfToken.php第46行中的TokenMismatchException [英] TokenMismatchException in VerifyCsrfToken.php line 46

查看:52
本文介绍了VerifyCsrfToken.php第46行中的TokenMismatchException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正尝试使用curl post方法提交表单.我已将csrf令牌正确设置为表单.

I am trying to submit a form using curl post method.I have set csrf token properly to the form.

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

但是它在VerifyCsrfToken.php line 46:中显示TokenMismatchException.我被共享主机卡住了,我将larvel 5项目包含在myapp文件夹中并将laravel public文件夹包含在public_html

But it shows TokenMismatchException in VerifyCsrfToken.php line 46:.I am stuck on it using shared hosting, i include my larvel 5 project in myapp folder and laravel public folder in public_html

作为测试,我还尝试了其他一些帖子建议将其注释掉的尝试 App\Http\Middleware\VerifyCsrfToken,在app/Http/kernal.php中 看看会发生什么.每次提交表单后,都会收到一条消息,提示您重定向到:/auth/login/auth/register,具体取决于我来自哪里,但没有成功.

As a test I have also tried as some other posts suggested commenting out App\Http\Middleware\VerifyCsrfToken, in app/Http/kernal.php to see what would happen. After doing this every time I submit a form I get a message which says redirecting to: /auth/login or /auth/register depending on where I came from with no success.

推荐答案

我找到了最适合我的解决方案.您需要做的是:

I found the best solution for me. What you need to do is:

转到->应用->例外-> Handler.php

并将其复制并粘贴到您的渲染方法中:

and copy and paste this in you render method:

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);
}

这将为您处理TokenMismatchException并在页面上显示友好消息:).希望它能帮助任何人!

This will handle the TokenMismatchException for you and display a friendly message on the page :). Hope it helps anyone out there!

这篇关于VerifyCsrfToken.php第46行中的TokenMismatchException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆