Z
Z
zhdoon2017-11-22 14:04:16
JavaScript
zhdoon, 2017-11-22 14:04:16

How to set a cookie using javascript so that it can be accessed both from the main domain and from all subdomains?

There is a main site in the Cyrillic domain http://site.rf . The site has many subdomains such as moscow.site.rf, peter.site.rf, etc. It is necessary that when entering the main site (or any of the subdomains), the cookie is checked, for example, region, and if it is not present, then it is filled in according to the subdomain region (region=msk, region=spb). In this case, it is necessary that this cookie be available on any subdomain, and not just on the one on which it was installed. How to do it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Z
zhdoon, 2017-11-22
@zhdoon

Maybe someone will find it useful
domain=site.com
The domain where the cookie is available. If not specified, then the current domain. It is acceptable to specify the current site.com domain and its subdomains, such as forum.site.com.
If you specify a special mask .site.com, then the cookie will be available on the site and all its subdomains. This is used, for example, in cases where the cookie contains authorization data and needs to be available on both site.com and forum.site.com.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question