如何配置symfony2会话生存期

时间:2016-01-20 09:29:33

标签: php symfony session

我正在尝试制作一个“记住我”复选按钮来修复用户会话的时间超过配置中指定的生命周期。我在NativeSessionStorage类的帮助下使用了symfony2会话生命周期。

$nativeSession = new NativeSessionStorage(
        array(
            'cookie_lifetime' => 3600*24*7
        )
    );

当我尝试启动我创建的会话时,symfony抛出此异常。

if($_SESSION){
        session_destroy();
        $nativeSession->start();
    }

enter image description here

enter image description here

任何人都有正确的程序宣布这种会议。

1 个答案:

答案 0 :(得分:3)

如果要在Symfony2中构建记住我的功能,可以在symfony2配置中为此功能定义更长的生命周期。有关其他信息,请参阅documentation。示例也取自那里。

# app/config/security.yml
security:
    # ...

    firewalls:
        main:
            # ...
            remember_me:
                secret:   '%secret%'
                lifetime: 604800 # 1 week in seconds
                path:     /
                # by default, the feature is enabled by checking a
                # checkbox in the login form (see below), uncomment the
                # following line to always enable it.
                #always_remember_me: true