Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 242
  • Last Modified:

read cookie from other domain?

Is it possible to read a cookie set by another domain?
The domains are owned by the same company! If so, how?
0
sargento
Asked:
sargento
  • 4
  • 4
1 Solution
 
bowkerCommented:
In a word, no ... cookies are sent back to a server by the browser AFTER it compares the name of the server to which it is sending a request with the name of the "covered domain" stored as part of the cookie.

So unless you can figure out (a) where the cookie file is kept, and (b) how to read that file, you can't get the value of a cookie for another domain.

If this is one company with two sites, you can set two cookies from each site  - one that the "setting" site will receive back, and one that the "other" site will receive back.  Convoluted, but depending on just exactly what you want to do, that may be the only way.

Bob.
0
 
bowkerCommented:
Another alternative: let all cookies be handled by one of the sites, and let the 2 servers talk to each other by FTP or via SQL ...
0
 
sargentoAuthor Commented:
what if the domain that was setting the cookie, created a second cookie, setting the domain variable to the second domain? Is that possible?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
ahosangCommented:
Try:
document.cookie="cookiename=value;expires=dateinGMT;domain=domainname";
Then your other domain that is stored will be able to read the cookie
0
 
sargentoAuthor Commented:
I couldn't get that to work!
0
 
bowkerCommented:
SARGENTO --

That's what I meant when I suggested, "you can set two cookies from each site  - one that the "setting" site will receive back, and one that the "other" site will receive back" ...

You could also set it up so that only 1 of the sites gets designated as the "covered domain"  - it receives all cookie responses, and your two servers talk with each other by FTP or use the same database table - then both servers have access to all statistics.

One major problem with this scenario ... server 1 sets a cookie with server 2 as the covered domain ... that cookie will not be recorded until the NEXT TIME that browser sends a request to server 2.

One solution ... server 1 sets its own cookies, server 2 sets its own cookies, and both servers record relevent data in a single database table on server 1.  Now your admin scripts, running on either server but using data from the database table on server 1, can summarize things for both sites ...

The bottom line, though, is that whatever you do will probably have to be done at the server level ... for security reasons, client-side code can't access another domain's cookie data.

Bob.
0
 
sargentoAuthor Commented:
How do I read all the other parameters set in a cookie? For example the domain and path of the cookie?
0
 
bowkerCommented:
It can't be done client-side, except for cookies that are relevent to the domain name for which the cookie was issued ... all other work will have to be done on the server using (e.g.) PHP or PERL ...

0
 
sargentoAuthor Commented:
That is what i mean! Cookies that were set by my domain. I want to look at the way it stores these parameters.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now