Re: Setting cookie on one domain for an other domain

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Peter Lauri wrote:

> Best group member,
> 
>  
> 
> When a user does a specific action on domain1.com I want a cookie to be
> set so that domain1.com and domain2.com can reach it. Ok, after reading
> the manual for setcookie() I tried this:
> 
>  
> 
> setcookie("thevariable", "thevalue", time()+60*60*24*30, "/",
> ".domain1.com");
> 
> setcookie("thevariable", "thevalue", time()+60*60*24*30, "/",
> ".domain2.com");
> 
>  
> 
> However, I can not detect the cookie at domain2.com.
> 
>  
> 
> A solution would be to just make a redirect to the other domain where the
> cookie is set and then return.
> 
>  
> 
> Question is: Can I not set a cookie at domain1.com to work at domain2.com?

This is a common problem, and the easiest solution, if you have control over
both domains, is to put a "bug" (a small image) on domain1 and domain2,
something like:

showlogo.php

Which returns a jpeg of an image. The trick is that you send it a parameter
such as:

http://domain2.com/showlogo.php?session=MYSESESSION

Then this code sets its cookie in domain2, so when you go there it is there.


You should try to use encryption, temp variables, or something to keep this
from being easy to hack.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux