Reading a cookie sent from a different server/domain

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

quilby
Forum Newbie
Posts: 13
Joined: Wed Jun 13, 2007 2:22 am

Reading a cookie sent from a different server/domain

Post 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!
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Cookies do not communicate across domains. You will need to figure out a different mechanism.
quilby
Forum Newbie
Posts: 13
Joined: Wed Jun 13, 2007 2:22 am

Post 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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

As I said, cookies are not communicated across domains.
markg85
Forum Commoner
Posts: 32
Joined: Sat Dec 03, 2005 6:49 pm

Post by markg85 »

perhaps sessions stored on the server can help with this?
i don't know it.. just a guess.
quilby
Forum Newbie
Posts: 13
Joined: Wed Jun 13, 2007 2:22 am

Post 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...
Last edited by quilby on Sat Oct 13, 2007 11:26 am, edited 1 time in total.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

You could handle this via the database and access it from a different domain.
quilby
Forum Newbie
Posts: 13
Joined: Wed Jun 13, 2007 2:22 am

Post by quilby »

What do you mean?

I want it so that the user does not have to log in.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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]]]]]] )
quilby
Forum Newbie
Posts: 13
Joined: Wed Jun 13, 2007 2:22 am

Post by quilby »

What if I want 10 domains to be able to access the cookie? Or even 1,000 domains. Can I do this?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

No. You cannot read cookies from other domains. Period.
quilby
Forum Newbie
Posts: 13
Joined: Wed Jun 13, 2007 2:22 am

Post by quilby »

Ok so is there any way to do what I mentioned in the reply above?
nickvd
DevNet Resident
Posts: 1027
Joined: Thu Mar 10, 2005 5:27 pm
Location: Southern Ontario
Contact:

Post by nickvd »

superdezign wrote:You could handle this via the database and access it from a different domain.
quilby
Forum Newbie
Posts: 13
Joined: Wed Jun 13, 2007 2:22 am

Post by quilby »

Yeah but I dont want the user to log in.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

quilby wrote:Yeah but I dont want the user to log in.
Whats that have to do with anything?
Post Reply