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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.