简体   繁体   中英

how to read a cookie from a php, when the cookie was set on a different sub-domain?

I have 2 sub-domains: 'secure' and 'downloads' of the same domain: "10.0.50.18".

on 'downloads' I set a cookie using jQuery like this:

$.cookie("width", w, {domain: "10.0.50.18"});

on 'secure', i am trying to read that cookie like this:

$width = $_COOKIE["width"];

yet it is not working.

can anyone help please? Thank you!

Cookies wont work across subdomains unless you specify when creating the cookie. You will need to do something like this:

$.cookie("width", w, {domain: ".mydomain.com"});

This will allow all sub domains of mydomain.com to share the cookie.

Sorry it is impossible to use cookies from different domains the way you are trying. some interesting proposals of solutions you can read here Cross-Domain Cookies

You can set a cookie to an IP address, you just cannot use wildcards with it.

domain .10.0.50.18 is not valid
domain 10.0.50.18 is valid

IP addresses do not easily follow organizational boundaries in the way DNS domains do. An IP address with a number one less or one greater than the IP address of the web server may not necessarily reside in the same organization. For security reasons any form of wild-carding of IP addresses in the domain attribute of a cookie is not permitted. This effectively removes the usefulness of the domain attribute for any form of IP address.

From http://www.ietf.org/rfc/rfc2109.txt

Fully-qualified host name (FQHN) means either the fully-qualified domain name (FQDN) of a host (ie, a completely specified domain name ending in a top-level domain such as .com or .uk), or the numeric Internet Protocol (IP) address of a host. The fully qualified domain name is preferred; use of numeric IP addresses is strongly discouraged .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM