dongxie7683 2015-03-03 08:46
浏览 57
已采纳

启用“记住我”时,在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.

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();

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

What is the proper way to log user out of Symfony 2 application? Do I need to additionally delete this cookie from server-side?

  • 写回答

4条回答 默认 最新

  • doubo4824 2015-03-03 08:57
    关注

    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
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 spring后端vue前端
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题