简体   繁体   中英

Zend Framework 2 (ZF2) auth session refresh using storage

I have looked all over and I can see where people have created the initial session for ZF2 auth, remember me's, etc, but I can't find where people are updating the session when there is activity. Basically, I already have an authentication (with doctrine) system and my current solution and I set up the following configuration setting:

return array (
    'session' => array(
        'cookie_lifetime' => 1800, // 30 min
        'remember_me_seconds' => 1800, // 30 min
        'use_cookies' => true,
    ),
);

Then what I am trying to do is RELOAD this on every request like this: NOTE: I have code that only does this if the user is already logged in.

class Module
{
    public function onBootstrap(EventInterface $e)
    {
        $this->getEventManager()->attach('route', array($this, 'onRoute'), -100);
    }

    public function onRoute(EventInterface $e)
    {
        $sessionConfig = new SessionConfig();
        $sessionConfig->setOptions($config['session']);
        $sessionManager = new SessionManager($sessionConfig);
        $sessionManager->rememberMe($config['session']['remember_me_seconds']);
        $sessionManager->start();
    }
}

My basic need is I'm trying to refresh the session (server and client) anytime there is a request, but 1. it feels like I'm re-creating it every time and 2. Sometimes the session seems to randomly die. I think this is because the original session dies after the 30 min I set it to.

Any advice?

PHP should be updating the session time for you, you don't need to do it manually.

Also, don't call rememberMe() on every request, as this will generate a new session token (assuming the session already exists).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM