Symfony 3: How to share a cookie on a subdomain?

I have over two subdomains on my site. such as: www.example.com, login.example.com, user.example.com, cart.example.com ... i setup cookie_domain -.example.com in config.yml and php.ini when I setCookies (' test ',' value ',' .example.com '), but cookie is not always used in the subdomain. so how to do it now?

there is my config.yml

session: handler_id: session.handler.native_file save_path: "%kernel.root_dir%/../var/sessions/" cookie_domain: .example.com cookie_lifetime: 0 name: TESTSESSIONID 

in my safety:

 security: session_fixation_strategy: none 
+5
source share
3 answers

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

config.yml

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

Hope for this help

0
source

You need to install trusted hosts in your application because, for security reasons, the Symfony application will respond to white hosts and subdomains. There are several ways you can fix this for this.

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

Below are links to documentation for reference purposes.

reference 1

reference 2

reference 3

0
source

I need this to work for all subdomains, but the domain itself changes depending on whether I developed or worked.

I use parameters_dev.yml and parameters.yml to define a "domain" and then added this to config.yml to allow cookies across all subdomains.

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

Source: https://habr.com/ru/post/1258449/


All Articles