Zend Framework 2 session life time

我只是一个虾纸丫 提交于 2019-12-05 10:24:22

Well I finaly found out what the issue was.

The problem was that I used

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

This "worked" the only issue was that there was set a cookie with the lifetime session. This ment different things in browsers. Ie in chrome it is destroyed if you close the tab, so no matter how high the gc_maxlifetime it would not work.

So an easy fix would be the following

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

Hope it would help some one in the futue

$config['authTimeout'] is a positive integer value

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

Change the value of 2419200 to how many seconds you actually want.

In application global.php or you can do it in module config:

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

check Zend\Session\Service\SessionConfig.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!