小编ebe*_*ent的帖子

Zend\Session\SessionManager和cookie_lifetime

我看到ZF2会话和超时的一些奇怪和令人沮丧的行为.

这是我用来设置会话的代码:

    $sessionConfig = new \Zend\Session\Config\StandardConfig();
    $sessionConfig->setOptions(array(
        'cache_expire' => 525949,
        'cookie_domain' => 'mydomain.com',
        'cookie_lifetime' => 31536000,
        'cookie_path' => '/',
        'cookie_secure' => TRUE,
        'gc_maxlifetime' => 31536000,
        'name' => 'mydomain',
        'remember_me_seconds' => 31536000,
        'use_cookies' => TRUE,
    ));

    $sessionManager = new \Zend\Session\SessionManager($sessionConfig);
    $sessionManager->rememberMe(31536000);
    $sessionManager->setSaveHandler(new \Zend\Session\SaveHandler\MongoDB($mongo, $options);
    $session = new \Zend\Session\Container('MY_SESSION', $sessionManager);
Run Code Online (Sandbox Code Playgroud)

当我执行此代码时,cookie将被创建,但过期是会话结束.

如果我改变这样的代码:

    $sessionManager = new \Zend\Session\SessionManager();
    $sessionManager->rememberMe(31536000);
    $sessionManager->setConfig($sessionConfig);
    $session = new \Zend\Session\Container('MY_SESSION', $sessionManager);
Run Code Online (Sandbox Code Playgroud)

cookie被创建,到期时间为一年.

但是,即使cookie仍然存在,会话仍会在30分钟左右后到期.

我想要的是cookie和会话持续一年.我如何在ZF2中实现这一目标?

php session-timeout zend-framework2

5
推荐指数
1
解决办法
3711
查看次数

标签 统计

php ×1

session-timeout ×1

zend-framework2 ×1