468,733 Members | 1,627 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,733 developers. It's quick & easy.

Cross-Domain Cookies

Hi I am trying to set up cross domain cookies on a server I have running
that currently has 2 domains running on it (on different IPs). Basically I
have a forums site (using UBB threads) and I want to users to be able to use
the forum login and password from the main site and then if they go to the
forum site they are already logged in to that as well.

I have tried followed this article:
http://www.phpbuilder.com/columns/ch...28.php3?page=3

What I have done is:
1. Put the following code at the top of the .php file where I create the
cookie (on the forum site) and in the .php file where my login code is on
the main site:

/////////////////////////////////////////////////////////
Support cross-domain cookies... */

// If the GET variable has been set, and it differs from the cookie
// variable, then use the get variable (and update the cookie)
global $HTTP_COOKIE_VARS, $HTTP_GET_VARS;
if (isset($sessionid) && isset($HTTP_GET_VARS['sessionid']) &&
($HTTP_COOKIE_VARS['sessionid'] != $HTTP_GET_VARS['sessionid'])) {
SetCookie('sessionid', $HTTP_GET_VARS['sessionid'], 0, '/', '');
$HTTP_COOKIE_VARS['sessionid'] = $HTTP_GET_VARS['sessionid'];
$sessionid = $HTTP_GET_VARS['sessionid'];
}
//////////////////////////////////////////////////////////

2. Set up the
domains['domain1'] = "http://<site domain>/-$sessionid-";
$domains['domain2'] = http://<forums domain>/-$sessionid-;
code in an file that is "required" by all the php scripts

3. Done the apache server stuff

However when I do something like
echo $domains['domain2'];
in the file where my login code is (on the main site) the output is:
http://<forums domain>/--
(there is no sessionid in the URL)
Could someone either tell me where I am going wrong or point me to another
article that maybe explains what I need to do a bit better. I am pretty
certian my problem is to do with teh $sessionid in step 1 above, I never set
it to equal anything so the code in the if statement never gets carried out.
I also just want to make sure that cross domain cookies can be used in this
situation

Anyway, any help would be much appriciated
Angus
Jul 17 '05 #1
1 8159
"Angus SC2" <a@b.com> wrote in message news:2q************@uni-berlin.de...
Hi I am trying to set up cross domain cookies on a server I have running
that currently has 2 domains running on it (on different IPs). Basically
I have a forums site (using UBB threads) and I want to users to be able to
use the forum login and password from the main site and then if they go to
the forum site they are already logged in to that as well.

I have tried followed this article:
http://www.phpbuilder.com/columns/ch...28.php3?page=3


Oops, that's the 3rd page I've posted, here is the proper URL:
http://www.phpbuilder.com/columns/ch...28.php3?page=1

Thanks
Angus
Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by rollasoc | last post: by
7 posts views Thread by Scott M. | last post: by
3 posts views Thread by jlamanna | last post: by
1 post views Thread by Rob Woodworth | last post: by
6 posts views Thread by Robert Bravery | last post: by
7 posts views Thread by Charles | last post: by
1 post views Thread by CARIGAR | last post: by
xarzu
2 posts views Thread by xarzu | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.