laravel "csrf" 问题 "Illuminate \ Session \ TokenMismatchException"
laravel "csrf" issue "Illuminate \ Session \ TokenMismatchException"
在 Laravel 我遇到了 "csrf" 问题 "Illuminate \ Session \ TokenMismatchException"
Route::group(array('before'=>'guest'),function()
{
Route::get('/user/create',array('uses'=>'UserController@getCreate'));
Route::get('/user/login',array('uses'=>'UserController@getLogin','as'=>'postCreate'));
Route::group(array('before'=>'csrf'),function()
{
Route::get('/user/create','UserController@postCreate');
Route::get('/user/login','UserController@postLogin');
});
});
即控制器
class UserController extends BaseController{
public function getCreate()
{
//return View::make('hello');
return View::make('user.register');
}
即视图
<div class="container">
<h1>Register</h1>
<form role="form" method="post" action="{{ URL::route('postCreate')}}">
<div class="form-gourp">
<label for="username">Username: </label>
<input id="username" name="username" type="text" class="form-control" />
</div>
<div class="form-gourp">
<label for="password">Password: </label>
<input id="password" name="password" type="text" class="form-control" />
</div>
<div class="form-gourp">
<label for="username">confirm Password: </label>
<input id="cpassword" name="cpassword" type="text" class="form-control" />
</div>
{{form::token()}}
<div class="form-gourp">
<input type="submit" value="register" class="btn btn-default"/>
</div>
</form>
当我添加{{form::token }}
时,它显示错误"Illuminate \ Session \ TokenMismatchException"
使用 {{ Form::open() }}
和 {{ Form::close() }}
而不是 <form>
标签
你的路线有误。
Route::group(array('before'=>'csrf'),function()
{
Route::get('/user/create','UserController@postCreate');
Route::get('/user/login','UserController@postLogin');
});
应该是post
,像下面这样
Route::group(array('before'=>'csrf'),function()
{
Route::post('/user/create','UserController@postCreate');
Route::post('/user/login','UserController@postLogin');
});
在 wiki and laravel doc 上阅读有关 CSRF 的更多信息。
在 Laravel 我遇到了 "csrf" 问题 "Illuminate \ Session \ TokenMismatchException"
Route::group(array('before'=>'guest'),function()
{
Route::get('/user/create',array('uses'=>'UserController@getCreate'));
Route::get('/user/login',array('uses'=>'UserController@getLogin','as'=>'postCreate'));
Route::group(array('before'=>'csrf'),function()
{
Route::get('/user/create','UserController@postCreate');
Route::get('/user/login','UserController@postLogin');
});
});
即控制器
class UserController extends BaseController{
public function getCreate()
{
//return View::make('hello');
return View::make('user.register');
}
即视图
<div class="container">
<h1>Register</h1>
<form role="form" method="post" action="{{ URL::route('postCreate')}}">
<div class="form-gourp">
<label for="username">Username: </label>
<input id="username" name="username" type="text" class="form-control" />
</div>
<div class="form-gourp">
<label for="password">Password: </label>
<input id="password" name="password" type="text" class="form-control" />
</div>
<div class="form-gourp">
<label for="username">confirm Password: </label>
<input id="cpassword" name="cpassword" type="text" class="form-control" />
</div>
{{form::token()}}
<div class="form-gourp">
<input type="submit" value="register" class="btn btn-default"/>
</div>
</form>
当我添加{{form::token }}
时,它显示错误"Illuminate \ Session \ TokenMismatchException"
使用 {{ Form::open() }}
和 {{ Form::close() }}
而不是 <form>
标签
你的路线有误。
Route::group(array('before'=>'csrf'),function()
{
Route::get('/user/create','UserController@postCreate');
Route::get('/user/login','UserController@postLogin');
});
应该是post
,像下面这样
Route::group(array('before'=>'csrf'),function()
{
Route::post('/user/create','UserController@postCreate');
Route::post('/user/login','UserController@postLogin');
});
在 wiki and laravel doc 上阅读有关 CSRF 的更多信息。