laravel 5.1 auth csrf令牌不匹配 [英] laravel 5.1 auth csrf token mismatch
问题描述
在做出任何判断之前,我先阅读了与我的问题有关的所有相关问题,但都没有解决它. 所以这是我的问题,当我使用laravel 5.1的身份验证功能并想要注册用户时,csrf令牌会在我请求显示我的注册表单时生成两次,而在我将表单数据发布到auth/register发布路由时会生成一个,因此我收到一个csrf令牌不匹配异常.这是我的注册表格标记
before make any judgment I read all the related questions related to my problem but none of them fixed it. so here's my problem when I use the authentication facility of laravel 5.1 and want to register a user the csrf token generate twice one when I requesting to show my register form and one when I post the form data to auth/register post route and this cause my to receive a csrf token mismatch exception. here's my register form markup
<form method="POST" action="/auth/register" class="ui large form">
{!! csrf_field() !!}
<div class="two fields dirright alignright">
<div class="field" >
<div class="ui right icon input">
<i class="user icon"></i>
{!! Form::text(
'first_name',
Input::old('first_name'),
array(
'class' => 'dirright alignright fontfamily',
'placeholder' => 'نام'
)
) !!}
</div>
</div>
<div class="field" >
<div class="ui right icon input">
<i class="user icon"></i>
{!! Form::text(
'last_name',
Input::old('last_name'),
array(
'class' => 'dirright alignright fontfamily',
'placeholder' => 'نام خانوادگی'
)
) !!}
</div>
</div>
</div>
<div class="field">
<div class="ui left icon input latintext">
<i class="mail icon"></i>
{!! Form::email(
'email',
Input::old('email'),
array(
'class' => 'latintext',
'placeholder' => 'E-mail address'
)
) !!}
</div>
</div>
<div class="field">
<div class="ui left icon input latintext">
<i class="lock icon"></i>
{!! Form::password(
'password',
Input::old('password'),
array(
'class' => 'latintext',
'placeholder' => 'Password'
)
) !!}
</div>
</div>
<div class="ui fluid large primary submit button">ثبت نام</div>
<div class="ui error message alignright"></div>
</form>
推荐答案
假设您的Web服务器已经具有对会话目录的写权限,在我的情况下为 'app/storage/framework/sessions/' .
Assume that your web server has already write access to session directory, in my case 'app/storage/framework/sessions/'.
执行:
$ rm -f {your_web_app}/storage/framework/sessions/*
这篇关于laravel 5.1 auth csrf令牌不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!