Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Setting a cookie with another domain?

by kidd (Curate)
on Aug 05, 2002 at 20:50 UTC ( #187814=perlquestion: print w/replies, xml ) Need Help??
kidd has asked for the wisdom of the Perl Monks concerning the following question:

Hey monks...

I have to sites with two different domain names and I have a script wich sets a cookie in one domain...but I want the second domain to be able and fetch that cookie?

Is there a way to do this or do I have to find another alternative?..


Replies are listed 'Best First'.
•Re: Setting a cookie with another domain?
by merlyn (Sage) on Aug 05, 2002 at 21:14 UTC
Re: Setting a cookie with another domain?
by Ovid (Cardinal) on Aug 05, 2002 at 21:28 UTC

    You'll have to find an alternative. Setting cookies for other domains would be a huge problem. Imagine a malicious programmer writing a script that would overwrite your cookies for any domain they wish. I'm sure that you can think of plenty of scenarious where this would be disastrous. For example, imagine someone changing your Web-based email account cookie so that you log into a spammer's account. Think of the new dimensions of spam that would be created ...


    Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

Re: Setting a cookie with another domain?
by sauoq (Abbot) on Aug 05, 2002 at 23:14 UTC
    As others have answered, you can't set a cookie with a different domain. That is a good thing.

    But, since you control both domains, you can redirect the browser to a URL in the other domain which then sets an identical cookie. If you need to keep the cookies in sync, it's a pain, but if the cookie doesn't change once it is set (e.g. just holds an ID) it's workable.

    Good luck!

    "My two cents aren't worth a dime.";
Re: Setting a cookie with another domain?
by BigLug (Chaplain) on Aug 06, 2002 at 01:50 UTC
    As people say .. you can't. However, try the following:
    1. Create a script on Server B. It would be something like:
    if ($ENV{HTTP_REFERER}=~/ServerA/) { print "Coookie: ".$ENV{QUERY_STRING}."\n\n"; }
    2. On Server A, whenever you set a cookie, send the cookie information to server B by using a javascript like:
    var temp=new Image; temp.src="http://ServerB/cgi-bin/$yourCookieString";
    The javascript will load the 'image', but it never displays it, thus you'll not get any strange errors. Server B will set the cookie when it is called. This might not work as is: I've not tried it. However the concept should work.
Re: Setting a cookie with another domain?
by kidd (Curate) on Aug 05, 2002 at 20:52 UTC

    I think I posted in the wrong catgory...sorry...

Re: Setting a cookie with another domain?
by nmerriweather (Friar) on Aug 06, 2002 at 03:23 UTC
    Are the cookies on the same server? If so, why not store the data server side -- so the data can be accessed with an md5 hash that you could print on both sites. If thats not what you're looking for... why not use a hidden frame in a frameset or iframe -- and use javascript to submit forms for both simultaneously?
      why not use a hidden frame in a frameset or iframe

      I got it to work that way, I created an iframe(0 width, 0 height) and I ran the script from there...

      Thanks for your help...

        If it is realy working please share this solution with me. Jack Peterson

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://187814]
Approved by hossman
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (8)
As of 2018-03-20 08:39 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (248 votes). Check out past polls.