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.

aynber
  • 22,380
  • 8
  • 50
  • 63
nigel
  • 181
  • 2
  • 11
  • The cookie won't change. You need to delete your cookie and log back. I just tested it, it works fine – goto Nov 03 '17 at 14:58
  • I deleted my cookie and now no cookie will come back but when i remove the cookie domain property i get a cookie – nigel Nov 03 '17 at 15:04
  • 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: SFSESSID` – goto Nov 03 '17 at 15:09

1 Answers1

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
goto
  • 7,908
  • 10
  • 48
  • 58
  • 4
    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`). – cadavre Apr 23 '18 at 10:51
  • Symfony 5.4 here, I had to do the same renaming thing to get login working. – diynevala Jun 26 '23 at 06:41