Cookie is setting twice (dublicated)
Posted
by Erik Larsson
on Stack Overflow
See other posts from Stack Overflow
or by Erik Larsson
Published on 2010-04-16T12:47:13Z
Indexed on
2010/04/16
12:53 UTC
Read the original article
Hit count: 228
I'm new to cookies, and im trying to set a cookie where to store the referer (the org ref).
But when i try this function:
function do_it_cookie() {
// Check if cookie exists
if (isset($_COOKIE['ref'])) {
// It dose exist, do nothing or anything...
} else {
setcookie ('ref', $_SERVER['HTTP_REFERER'], time() + 60, '/');
header ("Location: http://www.nyttforetag.com/mind-your-own-business/");
}
}
I want to store the cookie on the user computer for 30 days, if the return i want to know the initial refereeing url.
But when i use this and lets say i go to another page in my site and then go back to the homepage its sets a new cookie with the exact same name and with the ref of the previous page.
Is there away to avoid this?
© Stack Overflow or respective owner