Jump to content

Cookie problem


dagnasty

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.
Link to comment
https://forums.phpfreaks.com/topic/22212-cookie-problem/
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.
Link to comment
https://forums.phpfreaks.com/topic/22212-cookie-problem/#findComment-99432
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]
Link to comment
https://forums.phpfreaks.com/topic/22212-cookie-problem/#findComment-99621
Share on other sites

Archived

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

×
×
  • Create New...

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.