Reputation: 22958
I have a script where I set 2 cookies:
$month = time() + 60 * 60 * 24 * 30;
setcookie('id', $id, $month, '/');
setcookie('auth', $auth, $month, '/');
header('Content-Type: text/html; charset=utf-8');
print('<html><body>...etc....');
This does work well, but: some users have several id's, depending on from which page (social network) they access my script through an iframe.
A user having several id's is not a problem. But my problem is that when I ask that person to look at his cookies, he'll report that there are several cookies called id and auth. And I can reproduce it myself too.
And I was actually expecting there always to be just 1 id and 1 auth cookie.
What can I do here?
Doesn't calling setcookie('id', ...) with a new value replace the old value?
Thank you! Alex
Upvotes: 0
Views: 2210
Reputation: 57258
Cookies are based on a KV Scheme (Key=Value) concept and the Key's act as unique identifiers.
The three primary effectors of setcookie
are
setcookie("id","value")
$_COOKIE["id"]
setcookie("id","new value")
setcookie ("TestCookie", "", time() - 10);
so yes your correct in your question, you should have a look at other factors that may deter the cookie states.
Upvotes: 1