Jump to content

Archived

This topic is now archived and is closed to further replies.

dagnasty

Cookie problem

Recommended Posts

According to php.net this is supposed to work correctly

setcookie("cookie", $value, time()+31556926, "/", ".website.com", 1);

but doesn't, however this does:

setcookie("cookie", $value, time()+31556926);

The problem is that I need to set cookies for several domains. What's up with it? I don't seem to be missing anything.

Share this post


Link to post
Share on other sites
If you mean subdomains i.e www.example.com, example.example.com then by not specifying the domain value, you are telling the setcookie function to make the cookie available to all parts of example.com.

If your wanting to set multiple different domains with the same cookie i.e www.example.com, www.example2.com, to my knowledge it can't be done with the setcookie as the cookie is only available to the domain that the setcookie function is executed on.

Share this post


Link to post
Share on other sites

Correct. Multiple domains, not subdomains.

can anyone confirm this? what about through javascript?

Share this post


Link to post
Share on other sites
[code]<?php
setcookie("cookie", $value, time()+31556926, "/", ".website.com", 1);
?>[/code]

By setting "secure", the last parameter in your call, 1, a secure HTTPS connection is required for the cookie to be set.

[quote="php.net"]Secure: Indicates that the cookie should only be transmitted over a secure HTTPS connection. When set to TRUE, the cookie will only be set if a secure connection exists. The default is FALSE.[/quote]

so simply make it

[code]<?php
setcookie("cookie", $value, time()+31556926, "/", ".website.com");
?>[/code]

Share this post


Link to post
Share on other sites
Ahhh that's it. I was reading the wrong part of the setcookie page and thought the boolean was for something else.

Do you have any idea how I'd go about setting a cookie for a domain other than the one currently visited? It's not letting me do it right now.

Share this post


Link to post
Share on other sites
Does anyone have any idea how I could set cookies for multiple domains through 1 page?

I'm all out of ideas. I've tried using frames and iframes and it works in firefox but not in IE.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.