UBB.Dev
Posted By: bmh Setcookie for multiple sub-domains ? - 07/26/2002 11:47 AM
Hi Every one ,

first of all I was confused where i can post this problem, and I determined it as a hack, and I need your hand on this problem with my scritps


I will explain what i need :

let assume that I am running my UBB.Threads script under this url :
http://ubb.mydomain.com

and i have a chat script that i created it specially for UBB .. and its under this url :
http://chat.mydomain.com

Now my question is :

how i can set the cookies to be readable to the both url's ?

I tried the all possible ways that i know but nothing work fine with me

Note :
when i used "/" it will work for all directoris under that domain ,, but it will not work under the sub-domains !!

Any one can help with this problem


Thanks in advance 4 help

Regards
BMH
Posted By: JustDave Re: Setcookie for multiple sub-domains ? - 07/26/2002 2:51 PM
You would need to set the cookie using the main domain and a path of "/".

If you have 3 subdomains:

fun.mydomain.com
shop.mydomain.com
members.mydomain.com

The cookie would need the domain "mydomain.com" with the path "/" to be used when setting. I haven't played with cookies in a long time (a good thing) lol but the last time I had been I was getting problems from Netscape (forget what version) because it didn't seem to pick up on "mydomain.com" but it did work when I used ".mydomain.com" for the main domain. (but the problems I seemed to have had with netscape could have just been me) LoL

The syntax for setting a cookie is as follows:
setcookie ( string name [, string value [, int expire [, string path [, string domain [, int secure]]]]])

By looking at this I *think it may be possible to just add your main domain into the cookie path, divided by a coma. Example:

$config['cookiepath'] = "/,mydomain.com";

I hope this works for you.


Posted By: Dave_L_dup1 Re: Setcookie for multiple sub-domains ? - 07/26/2002 3:34 PM
$config['cookiepath'] = "/,mydomain.com";

Good idea, but that apparently doesn't work. That entire string gets interpreted as the 'path' parameter to setcookie(). By the way, if you try this, you may not be able to log in afterwards, so be prepared to manually edit config.inc.php to fix the path.

Also, if the 'domain' parameter is provided to setcookie(), the initial period is required: '.example.com', not 'example.com'.

I sent Rick another reminder yesterday that we need to be able to configure the cookie domain, or at least force it to be consistent. Let's all keep nagging him until this is done.
Posted By: JustDave Re: Setcookie for multiple sub-domains ? - 07/26/2002 3:45 PM
posted by Dave_L:
$config['cookiepath'] = "/,mydomain.com";

Good idea, but that apparently doesn't work. That entire string gets interpreted as the 'path' parameter to setcookie(). By the way, if you try this, you may not be able to log in afterwards, so be prepared to manually edit config.inc.php to fix the path.

Also, if the 'domain' parameter is provided to setcookie(), the initial period is required: '.example.com', not 'example.com'.



Ahhh ok... well go figure that IE didn't need the initial period to use the cookies... lol Thanks for clarifying though.

What would be needed is a seperate configurable variable such as $config['cookiedomain'] in the config.inc.php file and change all cookieset calls to use the domain variable.

Thanks for testing Dave_L
Posted By: bmh Re: Setcookie for multiple sub-domains ? - 07/26/2002 4:16 PM
First of all thanks for JustDave & Dave_L

Finally it's work

Dave_L :
Yes, what u said is right, but it will not work if u didnt specify the path , the domain only is not enough to solve the problem ...

so I end with :

setcookie ("TestCookie", "Myname", time() + 3600, "/", ".mydomain.com");

That will access all sub-domains & directories

as u can see , we have to determine the path & domain

but in our UBB.Threads script it's determined one of them !! either Path or Domain , I am not sure which one is determined


any way , hope scream can update this small thing, to include the both strings

and thank u again 4 help



Best Regards
BMH
© UBB.Developers