TokenMismatchException in VerifyCsrfToken.php line 53 in Laravel 5.1(Laravel 5.1 中 VerifyCsrfToken.php 第 53 行中的 TokenMismatchException)
问题描述
当我尝试登录时显示令牌错误.我在视图中检查了令牌是正确的,当评论 AppHttpMiddlewareVerifyCsrfToken::class
时,在 Kernel.php
它让我登录,但重定向到我的仪表板后我没有登录.我在 mac 上使用 MAMP.
<h1>登录</h1><div>{!!Form::open(['url'=>'user/login','class' =>'']) !!}<input type="hidden" name="_token" value="{{ csrf_token() }}"><ul><li><label>客户代码</label>{!!Form::Text('customer_code',Input::old('customer_code'),['class'=>''])!!}<li><label>密码</label>{!!Form::Password('password','',['class'=>''])!!}</li><li>{!!Form::submit('Submit',array('class' => 'btn')) !!}</li>{!!表格::关闭()!!}<div><a href="{!!URL::to('user/forget_password')!!}">忘记密码</a></div>
同时我使用Sentry Package
登录.
/*** 登录后*/公共函数 post_login(){尝试{$规则= ['customer_code' =>'必需的','密码' =>'必需的',];$消息 = ['customer_code.required' =>'错误1','password.required' =>'error2'];$validator = Validator::make(Input::all(), $rules,$message);如果 ($validator->fails()){return Redirect::back()->withErrors($validator)->withInput();}//如果 ($validator->fails())别的{$authUser = Sentry::authenticateAndRemember(array('customer_code' =>Input::get('customer_code'),'密码' =>Input::get('password')), false);如果($ authUser){//$login = Sentry::loginAndRemember($authUser);return Redirect::to('user/panel/'.$authUser->id)->with('comment', 'Welcome');}别的{return Redirect::back()->with('comment', '登录错误');}}//验证器}catch(Exception $e){return Redirect::back()->withInput(Input::except('password','file'))->withErrors(['ERROR!!!!!']);}}
已
由于您使用的是表单构建器,因此请从表单中删除它.当您执行 Form::open()
所以删除这一行:
When I try to login show me token error. I have checked token in view form it's right and when comment AppHttpMiddlewareVerifyCsrfToken::class
,
in the Kernel.php
it makes me login but after Redirect to my dashboard I'm not logged in. I am using MAMP on mac.
<div>
<h1>Login</h1>
<div>
{!! Form::open(['url'=>'user/login','class' => '']) !!}
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<ul>
<li><label>Customer Code</label>{!!Form::Text('customer_code',Input::old('customer_code'),['class'=>''])!!}</li>
<li><label>Password</label>{!!Form::Password('password','',['class'=>''])!!}</li>
<li>{!! Form::submit('Submit',array('class' => 'btn')) !!}</li>
</ul>
{!!Form::close()!!}
</div>
<div><a href="{!!URL::to('user/forget_password')!!}">Forget Password</a></div>
</div>
Meanwhile I use Sentry Package
for login.
/**
* post_login
*/
public function post_login()
{
try
{
$rules = [
'customer_code' => 'required',
'password' => 'required',
] ;
$message = [
'customer_code.required' => 'erorrr1',
'password.required' =>'error2'
];
$validator = Validator::make(Input::all(), $rules,$message);
if ($validator->fails())
{
return Redirect::back()->withErrors($validator)->withInput();
} // if ($validator->fails())
else
{
$authUser = Sentry::authenticateAndRemember(array(
'customer_code' => Input::get('customer_code'),
'password' => Input::get('password')), false);
if($authUser)
{
//$login = Sentry::loginAndRemember($authUser);
return Redirect::to('user/panel/'.$authUser->id)->with('comment', 'Welcome');
}
else
{
return Redirect::back()->with('comment', 'Error for login');
}
}//validator
}
catch(Exception $e)
{
return Redirect::back()->withInput(Input::except('password','file'))->withErrors(['ERROR!!!!!']);
}
}
Edited:
Since you are using Form builder remove this from your form. Laravel form builder automatically adds a hidden token field to your form when you do Form::open()
So remove this line:
<input type="hidden" name="_token" value="{{ csrf_token() }}">
这篇关于Laravel 5.1 中 VerifyCsrfToken.php 第 53 行中的 TokenMismatchException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Laravel 5.1 中 VerifyCsrfToken.php 第 53 行中的 TokenMis
基础教程推荐
- 使用 PDO 转义列名 2021-01-01
- Doctrine 2 - 在多对多关系中记录更改 2022-01-01
- 如何在 Symfony 和 Doctrine 中实现多对多和一对多? 2022-01-01
- 在 CakePHP 2.0 中使用 Html Helper 时未定义的变量 2021-01-01
- 在 yii2 中迁移时出现异常“找不到驱动程序" 2022-01-01
- PHP 守护进程/worker 环境 2022-01-01
- HTTP 与 FTP 上传 2021-01-01
- 如何在 XAMPP 上启用 mysqli? 2021-01-01
- phpmyadmin 错误“#1062 - 密钥 1 的重复条目‘1’" 2022-01-01
- 找不到类“AppHttpControllersDB",我也无法使用新模型 2022-01-01