登录用户出的Symfony 2应用程序时,"记得我"启用 [英] Log user out in Symfony 2 application when "remember me" is enabled
问题描述
我正在寻找一种方式来记录用户出的Symfony 2的应用程序,但无法找到一种方法,做正确。
I'm looking for a way to log user out of Symfony 2 application, but could not find a way to do it properly.
我试过这里介绍一种方法:
<一href=\"http://stackoverflow.com/questions/6464754/symfony2-how-to-log-user-out-manually-in-controller\">Symfony2:如何在控制了手动登录用户?
I've tried an approach described here: Symfony2: how to log user out manually in controller?
$this->get('security.context')->setToken(null);
$this->get('request')->getSession()->invalidate();
它的工作很好,当记得我被禁用,但是当我打开它,它不工作。它看起来像用户自动该cookie重新认证回来了。
It's working fine when "remember me" is disabled, however, when I enable it, it's not working. It looks like user is automatically re-authenticated back again by this cookie.
remember_me:
key: "%secret%"
lifetime: 31536000
path: /
domain: ~
always_remember_me: true
什么是记录用户出Symfony的2应用程序的正确方法?我是否需要额外删除服务器端的这个cookie?
What is the proper way to log user out of Symfony 2 application? Do I need to additionally delete this cookie from server-side?
推荐答案
您可能需要调用会话存储的保存()
(<一个href=\"http://api.symfony.com/master/Symfony/Component/HttpFoundation/Session/Storage/SessionStorageInterface.html#method_save\"相对=nofollow>文档)方法明确。
You may have to call the session-storage's save()
(Documentation) method explicitly.
强制会话中保存并关闭。
Force the session to be saved and closed.
此外,您可以要求删除会议 - 和/或 remember_me -cookies通过响应头
Further you can request to delete the session- and/or remember_me-cookies via response headers.
在会议 -cookie的名字被配置为容器参数 framework.session.name
键,默认为从session.name
价值您的的php.ini
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 );
在 remember_me -cookie的名字可以在安全配置
配置。
The remember_me-cookie's name can be configured in your security
configuration.
security:
firewalls:
your_firewall:
remember_me:
name: neverforget # <- cookie-name
这篇关于登录用户出的Symfony 2应用程序时,&QUOT;记得我&QUOT;启用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!