In the application I'm writing using a combination of development environments and languages, I have need of accessing a cookie from two different subdomains, each on a separate host.
The cookie is being set on www.mydomain.com
using the PHP code that follows, and I'm attempting to access it from distant.mydomain.com
on a separate host.
setcookie('token', base64_encode(serialize($token)), time()+10800, '/', '.mydomain.com');
I'm trying to access the cookie from distant.mydomain.com
using the following code:
if (isset($_COOKIE['token'])) { /* do stuff */ }
The problem: distant.mydomain.com
is not finding the cookie. The if
statement just mentioned returns false, even though the cookie exists.
I have verified that the cookie that is set is for mydomain.com
(by checking my Firefox cookies). I can't think of any reason this wouldn't be working.
Using the same setcookie
code, I have an old application running exclusively on the www.mydomain.com
host, and that application is able to access the cookie across domains. This makes me suspect that the problem has to do with separate hosts.
Just in case any of the following information is pertinent:
- www.mydomain.com
is IIS 6.0
- distant.mydomain.com
is Apache 2.2.9
- Both servers use PHP 5.2.x
- Both servers are operating on Windows Server 2003
If there is any further information I can provide in order to better describe the problem, please let me know!