我正在寻找一种方法来记录用户退出Symfony 2应用程序,但无法找到正确的方法.
我试过这里描述的方法:
Symfony2: how to log user out manually in controller?
$this->get('security.context')->setToken(null); $this->get('request')->getSession()->invalidate();
当“remember me”被禁用时,它工作正常,但是,当我启用它时,它不起作用.看起来这个cookie会再次自动重新验证用户.
remember_me: key: "%secret%" lifetime: 31536000 path: / domain: ~ always_remember_me: true
您可能必须显式调用session-storage的save()(
Documentation)方法.
Force the session to be saved and closed.
此外,您可以通过响应标头请求删除session-和/或remember_me-cookies.
session-cookie的名称配置为容器参数framework.session.name,默认为PHP.ini中的session.name值.
$cookieName = $this->container->getParameter('framework.session.name'); $response->headers->clearCookie( $cookieName );
可以在安全配置中配置remember_me-cookie的名称.
security: firewalls: your_firewall: remember_me: name: neverforget # <- cookie-name