Page 1 of 2

Reading a cookie sent from a different server/domain

Posted: Fri Oct 12, 2007 5:44 am
by quilby
I want to make it so that when a user logs on to site1.com he will get a cookie with a user ID, and then when he goes to site2.com (which is on a different domain and server), the site will know his user ID. Is there a way to do this by lets say putting a widget or something like that by site1.com on site2.com?

Thanks!

Posted: Fri Oct 12, 2007 9:34 pm
by feyd
Cookies do not communicate across domains. You will need to figure out a different mechanism.

Posted: Sat Oct 13, 2007 8:43 am
by quilby
Lets say a picture is which is hosted on site1.com is displayed on site2.com, can site1.com still read cookies from people browsing site2?

Posted: Sat Oct 13, 2007 9:08 am
by feyd
As I said, cookies are not communicated across domains.

Posted: Sat Oct 13, 2007 10:24 am
by markg85
perhaps sessions stored on the server can help with this?
i don't know it.. just a guess.

Posted: Sat Oct 13, 2007 11:23 am
by quilby
Ok, because I thought that there was away to get two domains to read the same cookie.

What I want to do is have user info stored on his browser so that when he leaves site1.com and goes to site2.com site2.com knows his UID and a couple more things, without having to ask him to log in.

Is there any other way to do this?

EDIT: BTW, the two websites are on different servers...

Posted: Sat Oct 13, 2007 11:25 am
by superdezign
You could handle this via the database and access it from a different domain.

Posted: Sat Oct 13, 2007 11:33 am
by quilby
What do you mean?

I want it so that the user does not have to log in.

Posted: Sat Oct 13, 2007 11:42 am
by John Cartwright
You can have the site create the cookie for both domains when it is created. Just make sure you set the domain parameter to the other server's domain.
bool setcookie ( string $name [, string $value [, int $expire [, string $path [, string $domain [, bool $secure [, bool $httponly]]]]]] )

Posted: Sat Oct 13, 2007 12:19 pm
by quilby
What if I want 10 domains to be able to access the cookie? Or even 1,000 domains. Can I do this?

Posted: Sat Oct 13, 2007 12:22 pm
by John Cartwright
No. You cannot read cookies from other domains. Period.

Posted: Sat Oct 13, 2007 12:25 pm
by quilby
Ok so is there any way to do what I mentioned in the reply above?

Posted: Sat Oct 13, 2007 1:36 pm
by nickvd
superdezign wrote:You could handle this via the database and access it from a different domain.

Posted: Sat Oct 13, 2007 4:51 pm
by quilby
Yeah but I dont want the user to log in.

Posted: Sat Oct 13, 2007 4:51 pm
by John Cartwright
quilby wrote:Yeah but I dont want the user to log in.
Whats that have to do with anything?