2013-10-22 29 views
5

我试图用\Zend\Session\Container来设置会话的最大生存时间。为了测试它,我把它放到1秒。现在Zend Framework 2会话生存时间

我看着docs

,所以我做

但没有成功。然后,我开始google搜索,发现this answer

所以,我提出的配置,以

return array(
    'session' => array(
     'remember_me_seconds' => 2419200, 
     'use_cookies' => true, 
     'cookie_httponly' => true, 
    ), 
); 

(的配置工作,并加载到经理),但同样没有成功

所以我继续搜索,发现this answer

但是再次没有成功。

因此,经过所有的搜索我无法得到它的工作,所以现在我希望其他人能够工作,并可以帮助我。

回答

6

那么我最终发现了问题所在。

问题是,我用

$sessionConfig = new SessionConfig(); 
$sessionConfig->setOptions(array(
    'use_cookies' => true, 
    'cookie_httponly' => true, 
    'gc_maxlifetime' => $config['authTimeout'], 
)); 
$manager = new SessionManager($sessionConfig); 

这种“合作”唯一的问题是,有设置cookie与寿命session。这在浏览器中不同。也就是说,如果你关闭标签页,它会被销毁,所以无论gc_maxlifetime有多高,它都不起作用。

所以,一个简单的办法是以下

$sessionConfig = new SessionConfig(); 
$sessionConfig->setOptions(array(
    'use_cookies' => true, 
    'cookie_httponly' => true, 
    'gc_maxlifetime' => $config['authTimeout'], 
    'cookie_lifetime' => $config['authTimeout'], 
)); 
$manager = new SessionManager($sessionConfig); 

希望这将有助于在futue

$config['authTimeout']一些一个是正整数

0
$config = new StandardConfig(); 
$config->setOptions(array(
    'cookie_lifetime' => '2419200', 
    'gc_maxlifetime' => '2419200' 
)); 

2419200的值更改为您实际需要的秒数。

+2

我想我需要设置配置到经理,然后经理到容器。如果是这样,它不适合我。我也尝试将StandardConfig更改为SessionConfig – MKroeders

0

在应用global.php也可以在模块配置做到这一点:

'session_config' => array(
    'name' => 'your session name', 
    'remember_me_seconds' => 60 * 60 * 24 * 30*3, 
    'use_cookies' => true, 
    'cookie_httponly' => true, 
), 

检查Zend的\会议\服务\ SessionConfig。

+0

您需要手动使用此配置。看看这里:https://stackoverflow.com/questions/12774809/how-to-bootstrap-sessions-in-zend-framework-2 – nepda