dpziir0079 2015-11-15 17:28
浏览 90

注销时,Symfony 2不会删除remember-me cookie

My goal is to do programmatically logout from controller. I use this nice solution. Everything works fine except that LONGSESS (renamed REMEMBERME) cookie not deleted. It deleted but not :)

Logout in controller code:

$response = $this->redirectToRoute('homepage');
$response->headers->clearCookie('LONGSESS');
return $response;

So, call this action.

  1. Request headers for this action (as expected):

    Cookie SESS=n4jbl1m61l6bceesbeusrbq044; LONGSESS=QXBwQnVuZGxlXEVudGl0eVxVc2VyOmRYTmxja0IxYzJWeUxtTnZiUT09OjE0NDgyMDMyMjQ6ZTFhNzBlNGEyMWM4NGM3N2UzYmI3ZmJiNWIzMGM5MDg2ZDAyOWY1ZGVhMWI4NTYyNGQ0OTJmNjVmNmRjOTY2NQ%3D%3D
    
  2. Response headers to this action (as expected):

    Set-Cookie:SESS=ai1gt79r49o184du3tknv7tdf6; path=/; domain=.myhost.local
    Set-Cookie:LONGSESS=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0; path=/; httponly
    Set-Cookie:SESS=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0; path=/; httponly
    
  3. Redirect headers (as expected):

    Location:/app_dev.php/
    
  4. Next request headers to homepage (NOT as expected - LONGSESS value is the same as previous request):

    Cookie:LONGSESS=QXBwQnVuZGxlXEVudGl0eVxVc2VyOmRYTmxja0IxYzJWeUxtTnZiUT09OjE0NDgyMDMyMjQ6ZTFhNzBlNGEyMWM4NGM3N2UzYmI3ZmJiNWIzMGM5MDg2ZDAyOWY1ZGVhMWI4NTYyNGQ0OTJmNjVmNmRjOTY2NQ%3D%3D; SESS=ai1gt79r49o184du3tknv7tdf6
    

So user is not logged out.

How may it be? LONGSESS cookie set to deleted, expired but next request has the same value?

  • 写回答

2条回答 默认 最新

  • douqi2804 2015-11-15 18:46
    关注

    The solution is to set third argument domain in clearCookie method call. It have to be equals to domain in session settings:

    framework:
        session:
            cookie_domain: YOUR-DOMAIN.COM
    

    and

    firewalls:
        your_firewall:
                remember_me:
                    domain: YOUR-DOMAIN.COM
    

    So, the right way:

    $response->headers->clearCookie('LONGSESS', '/', 'YOUR-DOMAIN.COM');
    
    评论

报告相同问题?

悬赏问题

  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探