I want to store a cookie, using PHP, containing the number of pageviews for a user. This is my code:
if (!isset($_COOKIE['visits'])) $_COOKIE['visits'] = 0;
$visited = $_COOKIE['visits'] + 1;
setcookie('visits', $visited, time() + $h * 3600, "/");
For some reason, the counter increases by 2 instead of 1. Where is the bug?