Symfony 3: How to share the cookie on subdomain? Symfony 3: How to share the cookie on subdomain? symfony symfony

Symfony 3: How to share the cookie on subdomain?


You can configure the session key in the config.yml defining a cookie_domain. As example:

config.yml

session:    cookie_lifetime: 0    save_path: %kernel.root_dir%/var/sessions    cookie_domain: .my-domain.com    name: SFSESSID

Hope this help


You need to set trusted hosts in your application because for security reason symfony application will respond to whitelisted hosts and subdomins. To do this you have couple of ways to fix it

  1. In your config.yml set trusted_hosts like below
#app/config/config.ymlframework:    trusted_hosts:  ['example.com', 'login.example.com', 'user.example.com', 'cart.example.com']
  1. You can also set the trusted hosts in the front controller using the Request::setTrustedHosts() method like below.
//web/app.php Request::setTrustedHosts(array('.*\.?example.com$'));

Please find below documentation links are for reference purpose

reference 1

reference 2

reference 3


i needed this to work for all subdomains, but the domain itself changed depending on whether i was developing or in production.

I use parameters_dev.yml and parameters.yml to define the 'domain', then added this in config.yml to allow cookies accross all subdomains.

framework:session:    cookie_domain: '.%domain%'