6

Cookies & amp; cookie domains

 2 years ago
source link: https://www.codesd.com/item/cookies-cookie-domains.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Cookies & amp; cookie domains

advertisements

I have two servers: the live server (mydomain.com) and the QA server (qa.mydomain.com). When I set cookies I set the domain as respectively ".mydomain.com" and ".qa.mydomain.com". One of these cookies, called "session_id" is used for authentication and login purposes. It is obvious that a cookie for one domain will not work on the other. However as I am prepending the dot to the domain PHP sometimes reads the ".domain.com" cookie on the QA server with the result that I am not able to login.

Are there ways to have PHP read the correct cookie?


See http://se2.php.net/setcookie

The domain that the cookie is available to. To make the cookie available on all subdomains of example.com (including example.com itself) then you'd set it to '.example.com'. Although some browsers will accept cookies without the initial ., » RFC 2109 requires it to be included. Setting the domain to 'www.example.com' or '.www.example.com' will make the cookie only available in the www subdomain.

You say:

It is obvious that a cookie for one domain will not work on the other.

when .mydomain.com should match all subdomains. I would remove the dot.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK