For example, code such as the following does not seem to work even if the cookie is actually set until I refresh the page.
setcookie("cookies","1", time()+ 86400,"/" );
if (!isset($_COOKIE["cookies"])) {
$cookies = "foobar";
}
I am trying to write an accurate "unique user" counter on my site, which works on the basis of checking if the user has a cookie installed on the computer, if they do not, he does +1 and sets the cookie. The problem is that users without cookies will only +1 on each page load, so naturally, I only want to run this code for those who have cookies.
However, the cookie checker above always returns $ cookies = "foobar" when the first page loads, regardless of who has cookies or not. Therefore, if the user simply views 1 page of the site, their visit will not be registered by the counter.
user15063
source
share