Session cookies operating under a subdomain

How to make session cookies work / be available in the domain and subdomains?

+4
source share
3 answers

For session cookies, you need to override cookie settings:

So you can use:

ini_set('session.cookie_domain', '.website.com'); 

or

 session_set_cookie_params(0, '/', '.website.com'); 

"." on the front panel makes it available under the domain and subdomains.

Note. You will need to delete all existing cookies from your browser for the domain you are working with so that they can be correctly initialized to work.

+3
source

If you set a cookie for the "top" domain (example.com), the cookie will also apply to subdomains (sub.example.com, another.example.com).

Aside, this is the reason why some larger companies use completely separate domains to serve static materials, for example, stackoverflow uses http://sstatic.net/

+1
source

I assume you are using setcookie (). If so, just set a cookie for ".domain.com".

 setcookie("testcookie", "1", 0, "", ".domain.com"); 
+1
source

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


All Articles