Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Setting a cookie with another domain?

by kidd (Curate)
on Aug 05, 2002 at 20:50 UTC ( [id://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?..


Thanks

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 ...

    Cheers,
    Ovid

    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!

    -sauoq
    "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 setcookie.pl 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/setcookie.pl?$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
    Ooops...

    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?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://187814]
Approved by hossman
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (6)
As of 2024-03-19 07:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found