Log user out in Symfony 2 application when “remember me” is enabled

后端 未结 3 1374
孤街浪徒
孤街浪徒 2020-12-09 19:55

I\'m looking for a way to log user out of Symfony 2 application, but could not find a way to do it properly.

I\'ve tried an approach described here: Symfony2: how to

3条回答
  •  余生分开走
    2020-12-09 20:49

    You may have to call the session-storage's save() (Documentation) method explicitly.

    Force the session to be saved and closed.

    Further you can request to delete the session- and/or remember_me-cookies via response headers.

    The session-cookie's name is configured as the container-parameter framework.session.name and defaults to the session.name value from your php.ini.

    $cookieName = $this->container->getParameter('framework.session.name');
    $response->headers->clearCookie( $cookieName );
    

    The remember_me-cookie's name can be configured in your security configuration.

    security:
        firewalls:
            your_firewall:
                remember_me: 
                    name: neverforget # <- cookie-name
    

提交回复
热议问题