symfony - Silex:设置防火墙 session 生命周期

标签 symfony silex

我正在尝试延长用户登录后的默认生命周期。对于登录,我使用安全服务提供商,如下所示:

    $app = $this->_app;             
    $this->_app->register(new Silex\Provider\SecurityServiceProvider(), array(
        'security.firewalls' => array(
            'default' => array(
                'pattern' => '^.*$',
                'anonymous' => true, // Needed as the login path is under the secured area
                'form' => array('login_path' => '/signup/', 'check_path' => 'login_check', 'failure_path' => 'login_failure'),
                'logout' => array('logout_path' => '/logout/'), // url to call for logging out
                'users' => $this->_app->share(function() use ($app)
                    {
                        // Specific class App\User\UserProvider is described below
                        return new UserProvider($app['db']);
                    }),
            ),
        ),
        'security.access_rules' => array(
            array('^/restricted/$', 'ROLE_USER'),
        )
    ));

我尝试设置 session 生命周期(cookie),如下所示:

    $this->_app->register(new Silex\Provider\SessionServiceProvider(), array(
        'session.storage.options' => array('cookie_lifetime' => (60 * 60 * 12)), // 12 hours
    ));

但还是什么都没有。 session 在 15 分钟左右后自行删除。

如何将登录安全防火墙的生命周期延长至 12 小时?

最佳答案

我想我终于开始工作了:

在数据库中保存 session 似乎可以解决问题。

SQL:

  CREATE TABLE `session` (
      `session_id` varchar(255) NOT NULL,
      `session_value` text NOT NULL,
      `session_time` int(11) NOT NULL,
      PRIMARY KEY (`session_id`)
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8;

PHP:

    /* SESSION IN DB */
    $this->_app->register(new Silex\Provider\SessionServiceProvider());
    $this->_app['session.db_options'] = array(
        'db_table' => 'session',
        'db_id_col' => 'session_id',
        'db_data_col' => 'session_value',
        'db_time_col' => 'session_time',
    );
    $this->_app['session.storage.handler'] = $this->_app->share(function ()
        {
            return new PdoSessionHandler(
                $this->_app['db']->getWrappedConnection(), $this->_app['session.db_options'], $this->_app['session.storage.options']
            );
        });

关于symfony - Silex:设置防火墙 session 生命周期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14601002/

相关文章:

php - 交响乐 2.8 : Doctrine getManagerForClass() not returning the right Entity Manager

session - 使用 Silex SessionServiceProvider 时 PHPUnit 失败

php - 带有 Silex PHP : good choice? 的 RESTful 网络服务

symfony - 带有 Doctrine ORM 的 Silex 身份验证系统

php - Twig 不更新 symfony 中的更改

php - 为什么 Symfony 表单不使用约束注释验证我的 DTO?

javascript - 尝试在函数中使用参数时出错

php - 使用 Symfony 2 创建表单步骤?

php - Silex 中的自定义 BaseController

php - php错误显示空白页