in reply to Help reading cookies

Shouldn't this code tell it to read the cookie on the domain it's called from?
No. Regardless of whether you code your own solution or use a module, your script has no control over this. Cookies persist on the client side (browser) and are returned to the server with each request. How the browser is configured may modify the expected behavior, but it would be unusual for a browser to return a cookie to any but its originating domain (at least it should be).

Replies are listed 'Best First'.
Re^2: Help reading cookies
by htmanning (Friar) on Nov 23, 2008 at 08:49 UTC
    Can I read a cookie from another domain? Here's the deal. My script resides at www.mymaindomain.com, but it gets called from www.myfirstdomain.com, or myseconddomain.com. Each domain hosts an install of phpbb so if someone is at myfirstdomain.com, and they click to post a comment, it goes to my script at www.mymaindomain.com. That's why when my cookie routine looks for the cookie, it's actually looking at mymaindoman.com instead of mymaindomain.com.

    Make sense? Is there any way for me to tell the script which domain to look at? Like the one that makes the call?

    Thanks.

      Is there any way for me to tell the script which domain to look at? Like the one that makes the call?

      No.

      If it is the "wrong" domain then the script won't even receive the cookie.

      The client's browser won't send it. This is out of your control.

      Steve
      --
        Well, what about having a script called check-cookie.pl at every domain? The user clicks a link to go to www.mymaindomain/cgi-bin/comments.pl and that somehow passes off to myfirstdomain/cgi-bin/check-cookie.pl which would include this:

        local(@getcookies) = split (/; /,$ENV{'HTTP_COOKIE'}); local(%cookies); foreach(@getcookies){ ($ckey, $cval) = split (/=/,$_); $cookies{$ckey} = $cval; } #end foreach(@getcookies) $user_sid = $cookies{'phpbb2mysql_sid'}; $user_logged = $cookies{'phpbb2mysql_data'}; $user_lang = $cookies{'lang'}; if ($user_logged !~ /autologin/) { print "$user_logged"; &error(not_logged); }

        That would check the local cookie on that domain before passing back to the www.mymaindomain/cgi-bin/comments.pl script again. Shouldn't that work?

        My only problem now is, how do I pass it off? I have a require line in the comments.pl that takes it to the check-cookie.pl script at myfirstdomain.com, but it doesn't read the cookie.