I’m trying to set up a cookie that, for each visit to a page, counts to 12, and then starts over at one again.
// if there is no cookie, set one or if it's greater than 12, set it back to one since there's only 12 images
if(!isset($_COOKIE['c_idximg']) || ($_COOKIE['c_idximg'] > 12)) {
setcookie("c_idximg",1, time()+86400*7); }
else {
// next page visit, it already exist, so advance it by one
$imgNUM = $_COOKIE['c_idximg'];
$imgNUM = $imgNUM + 1; // advance by one
setcookie("c_idximg",$imgNUM, time()+86400*7);
}
// output the values to see what they are!!
echo $imgNUM.' this is imgNUM<br>';
echo $_COOKIE["c_idximg"].' this is the cookie'; // this is ONE MORE than "imgNUM". WTH??
What’s freaking me out here, when I output the two values as above:
- “$imgNUM” is always one value higher than the cookie value.
- The cookie will count to 13 before resetting to one.
Uhhh, I’m probably an idiot, but what’s going on there that I don’t get?
edit: obviously I have no idea how to spell “Advnace” …