Solved

read cookie from other domain?

Posted on 2001-08-27
9
229 Views
Last Modified: 2008-01-09
Is it possible to read a cookie set by another domain?
The domains are owned by the same company! If so, how?
0
Comment
Question by:sargento
  • 4
  • 4
9 Comments
 
LVL 1

Expert Comment

by:bowker
ID: 6430111
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
 
LVL 1

Expert Comment

by:bowker
ID: 6430114
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
 

Author Comment

by:sargento
ID: 6430204
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
 
LVL 12

Expert Comment

by:ahosang
ID: 6430215
Try:
document.cookie="cookiename=value;expires=dateinGMT;domain=domainname";
Then your other domain that is stored will be able to read the cookie
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

Author Comment

by:sargento
ID: 6430243
I couldn't get that to work!
0
 
LVL 1

Accepted Solution

by:
bowker earned 200 total points
ID: 6430259
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
 

Author Comment

by:sargento
ID: 6430314
How do I read all the other parameters set in a cookie? For example the domain and path of the cookie?
0
 
LVL 1

Expert Comment

by:bowker
ID: 6430345
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
 

Author Comment

by:sargento
ID: 6430362
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now