我有一个问题,因为1周或多或少,当我离开我的应用程序的页面,但没有使用它可能4或5小时,并返回作出请求(在点击一个按钮来加载的东西或类似的东西),每次在控制台中显示此:Laravel 4,使用CSRF过滤器.php中的令牌不匹配异常使用CSRF
{
"error":{
"type":"Illuminate\\Session\\TokenMismatchException",
"message":"",
"file":"C:\\xampp182\\htdocs\\mysite\\app\\filters.php",
"line":97
}
}
我使用CSRFprotección我通过为Ajax请求该配置
$.ajax({
url: '/path/to/file',
type: 'default GET (Other values: POST)',
dataType: 'default: Intelligent Guess (Other values: xml, json, script, or html)',
data: {param1: 'value1'},
headers: {
'X-CSRF-Token': $('meta[name="csrf-token"]').attr('content')
},
})
.done(function() {
console.log("success");
})
.fail(function() {
console.log("error");
})
.always(function() {
console.log("complete");
});
POST请求
这是我的filters.php
/*
|--------------------------------------------------------------------------
| CSRF Protection Filter
|--------------------------------------------------------------------------
|
| The CSRF filter is responsible for protecting your application against
| cross-site request forgery attacks. If this special token in a user
| session does not match the one given in this request, we'll bail.
|
*/
Route::filter('csrf', function($route, $request)
{
if (strtoupper($request->getMethod()) === 'GET')
{
return; // get requests are not CSRF protected
}
$token = Request::ajax() ? Request::header('x-csrf-token') : Input::get('_token');
if (Session::token() != $token)
{
throw new Illuminate\Session\TokenMismatchException; //Line 97
}
});
编辑
我看到了问题,对话::令牌()和$令牌是不同的,但有没有办法再生或者把两个标记具有相同的价值?
也许,这个答案是有帮助的。 [上登录令牌不匹配异常(Laravel)] [1] [1]:HTTP://计算器。COM /问题/ 22066241 /令牌不匹配,异常的登录-laravel/28361491#28361491 – 2015-02-06 08:34:12