【问题标题】:Laravel 4.2 Generate CSRF Token with expiration timeLaravel 4.2 生成具有过期时间的 CSRF Token
【发布时间】:2016-05-31 16:04:09
【问题描述】:

我需要在控制器内部创建具有特定过期时间的 csrf 令牌。

return csrf_token();

我试着这样做csrf_token('300')

但我不确定它是否将 csrf_token 过期时间设置为 300 秒。

这样,csrf_token('300') 在 Laravel 4.2 中生成具有过期时间的 csrf_token 的正确方法吗?

【问题讨论】:

    标签: php laravel csrf laravel-4.2


    【解决方案1】:

    如果您检查功能,会说这不起作用:

        //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

    【讨论】:

    猜你喜欢
    • 2019-01-22
    • 1970-01-01
    • 1970-01-01
    • 2014-11-01
    • 1970-01-01
    • 2013-03-31
    • 2018-11-06
    • 2018-10-20
    • 2015-05-14
    相关资源
    最近更新 更多