Symfony 3 sharing cookies across sub-domains?
Asked Answered
C

1

8

I want to share a cookie across any subdomain. This should then allow me to keep the session. I am using the Symfony framework version 3.0.

I've read that you should set the following:

## app/config/config.yml
   session:
       cookie_domain: .localhost

I tried multiple variations on this but none of them change anything. the domain associated with the cookie won't change. Any ideas how this should be done?? What am I missing.

Cataclinal answered 3/11, 2017 at 14:36 Comment(3)
The cookie won't change. You need to delete your cookie and log back. I just tested it, it works fineWoolson
I deleted my cookie and now no cookie will come back but when i remove the cookie domain property i get a cookieCataclinal
I found a gist where the user use thoses params, can you try? cookie_lifetime: 0 save_path: %kernel.root_dir%/var/sessions cookie_domain: .my-domain.com name: SFSESSIDWoolson
W
13

To be sure you need to delete your cookie and log back.

session:
    cookie_lifetime: 0
    save_path: %kernel.root_dir%/var/sessions
    cookie_domain: .my-domain.com
    name: SFSESSID
Woolson answered 3/11, 2017 at 14:55 Comment(2)
This works flawlessly. Please remember to remove your cookie storage before next login or you won't be able to login (with CSRF enabled). This is also a problem on already-deployed systems (you won't ask your users to clear their cookies, right?), so easiest solution is to change session.name parameter to other than previous (in most cases PHPSESSID).Jelly
Symfony 5.4 here, I had to do the same renaming thing to get login working.Font

© 2022 - 2024 — McMap. All rights reserved.