Cookies across subdomains and hosts

后端 未结 5 2246
被撕碎了的回忆
被撕碎了的回忆 2021-02-19 01:05

In the application I\'m writing using a combination of development environments and languages, I have need of accessing a cookie from two different subdomains, each on a separat

5条回答
  •  旧时难觅i
    2021-02-19 01:27

    From php.net about the setCookie-function:

    The path on the server in which the cookie will be available on. If set to '/', the cookie will be available within the entire domain . If set to '/foo/', the cookie will only be available within the /foo/ directory and all sub-directories such as /foo/bar/ of domain . The default value is the current directory that the cookie is being set in.

    The domain that the cookie is available. To make the cookie available on all subdomains of example.com then you'd set it to '.example.com'. The . is not required but makes it compatible with more browsers. Setting it to www.example.com will make the cookie only available in the www subdomain. Refer to tail matching in the » spec for details.

    Basically: Your 4. and 5. parameter needs to be checked: Well, your path seems to be fine, but the domain needs to be changed:

    Today you block the cookie to all others than domain A, but you want it to be awailable to both domain A and B. This is a bit tricky, but can be solved. Get inspiration on 15seconds ;-)

提交回复
热议问题