Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

read cookie from other domain?

Posted on 2001-08-27
9
Medium Priority
?
240 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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
 

Author Comment

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

Accepted Solution

by:
bowker earned 800 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

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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…

610 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