daniels
daniels

Reputation: 19203

Can you set a cookie only for domain.tld and www.domain.tld?

Can you set a cookie only for domain.tld and www.domain.tld so that if you go to any other subdomain (bla.doamin.tld for example) the cookie won't be set?

Upvotes: 0

Views: 1609

Answers (3)

Joe Freeman
Joe Freeman

Reputation: 3816

You can do this. It's mentioned in this cookie spec: http://curl.haxx.se/rfc/cookie_spec.html

When searching the cookie list for valid cookies, a comparison of the domain attributes of the cookie is made with the Internet domain name of the host from which the URL will be fetched. If there is a tail match, then the cookie will go through path matching to see if it should be sent. "Tail matching" means that domain attribute is matched against the tail of the fully qualified domain name of the host. A domain attribute of "acme.com" would match host names "anvil.acme.com" as well as "shipping.crate.acme.com".

Upvotes: 0

Philippe Gerber
Philippe Gerber

Reputation: 17836

I think this isn't possible. I would abstract your cookie-setting-functionality and just set two cookies. One for www.example.org and one for example.org.

Upvotes: -1

user114767
user114767

Reputation:

Only if you specify .domain.tld a cookie works for all sub-domains. Setting the cookie for www.domain.tld AND domain.tld should be just what you need.

Upvotes: 2

Related Questions