我需要在控制器内创建具有一定过期时间的csrf令牌。
return csrf_token();
我试着这样做csrf_token('300')
但我不确定它是否将csrf_token到期时间设置为 300 秒。
这样,csrf_token('300')
在 Laravel 4.2 中生成过期时间csrf_token的正确方法吗?
如果您检查函数,会说这不起作用:
//framework/src/Illuminate/Support/helpers.php
function csrf_token()
{
$session = app('session');
if (isset($session))
{
return $session->getToken();
}
throw new RuntimeException("Application session store not set.");
}
它没有参数。但是您可以实现自己的csrf_token帮助程序。
在当前实现中,应使用新会话续订令牌。也许您可以重新生成会话 ID 以获取新的 csrf 令牌。
https://laracasts.com/discuss/channels/general-discussion/session-lifetime-timeout-and-csrf-token-mismatch