Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting a cookie on a different domain

Status
Not open for further replies.

webmigit

Programmer
Joined
Aug 3, 2001
Messages
2,027
Location
US
Lets say I have two domains...

MySite.com
Example.com

And I want to set a cookie on example.com that can be read by mysite.com, I don't care if it can be read by example.com.

I thought this would be the code I would use to achieve this:

<cfcookie
expires=&quot;never&quot; name=&quot;hiname&quot;
domain=&quot;.mysite.com&quot; value=&quot;steve&quot;>

All this code seems to do is require the user to be on mysite.com before the cookie can be set. Both domains are on the same server.

If I run example.com/setcook.cfm nothing happens, but if I run mysite.com/setcook.cfm the cookie is set for mysite. Problem is that does me absolutely no good.

Anyone got a solution to set this cookie? Just trying to set a simple firstname.

ALFII.com
---------------------
If this post answered or helped to answer your question, please reply with such so that forum members with a similar question will know to use this advice.
 
I always learned that cookies from one domain could not be read by another domain, period. That's part of the built-in security of cookies... at least, that's my understanding.

In fact, without the SETDOMAINCOOKIES attribute set on your CFAPPLICATION tag, ColdFusion won't even allow you to share cookies across subdomains.

What if the page on example.com loaded in the setcook.cfm page from mysite.com in a hidden frame (or iframe) or perhaps a pop-up that immediately closes itself.

I believe that's the way the ad tracker agencies do it. Since the browser is actually hitting mysite.com, you should be able to set a cookie for that domain... even though the user is actually visiting example.com.

OR... I don't know what you're wanting to do with the cookie, but perhaps you can do it without using cookies... perhaps having the example.com page call a webservice from mysite.com (or vice versa) to share information.


-Carl
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top