Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony 3 sharing cookies across sub-domains?

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.

like image 928
nigel Avatar asked Nov 03 '17 14:11

nigel


People also ask

Can you share cookies across subdomains?

To share cookies across subdomains, you can simply create cookies with the domain directive set to the parent domain, in this case, example.com, rather than either of the specific subdomains.

Can you share cookies between domains?

To share a cookie between domains, you will need two domains, for example myserver.com and slave.com . One of the domains will issue the cookies and the other domain will ask the first domain what cookie should be issued to the client.

Do cookies apply to subdomains?

That is, if the domain name in your cookie's domain parameter doesn't start with a period, then it will not let subdomains read that cookie. If it does start with the period, then all subdomains will have full access to that cookie's value.

Are cookies valid for subdomains?

If you set a Domain attribute to the exact subdomain (e.g. application.example.com ), your browser will still interpret it as a wildcard, making the cookie valid for the subdomain and all of its subdomains (as in, it'll show up as .


1 Answers

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
like image 94
goto Avatar answered Sep 22 '22 02:09

goto