Tjorriemorrie Posted May 23, 2008 Share Posted May 23, 2008 hey everyone! Got this little cookie problem. Basically suppose to work like a count for the total number of pages the user have loaded. Somehow the value never gets past 2. So freakin weird. Please help: if (isset($_COOKIE['totalCount'])) { $_COOKIE['totalCount']++; } else { setcookie('totalCount', 1, time()+60); } It works for the session though: if (empty($_SESSION['count'])) { $_SESSION['count'] = 1; } else { $_SESSION['count']++; } Don't know why the cookie gets stuck at 2 Quote Link to comment Share on other sites More sharing options...
Rohan Shenoy Posted May 23, 2008 Share Posted May 23, 2008 After obtaining and incrementing the value from the cookie, you should write it back to the cookie, which you aren't doing. Quote Link to comment Share on other sites More sharing options...
Tjorriemorrie Posted May 27, 2008 Author Share Posted May 27, 2008 Thanks! It's still not working though, but I've tried the following so it must be wrong somewhere? if (isset($_COOKIE['totalCount'])) { $cookInc = $_COOKIE['totalCount']++; setcookie('totalCount', $cookInc, time()+60000); } else { setcookie('totalCount', 1, time()+60000); } I think the cookie doesn't save or something It keeps being at 1. Am I setting it correctly? Quote Link to comment Share on other sites More sharing options...
Tjorriemorrie Posted May 27, 2008 Author Share Posted May 27, 2008 [solved] this works: if (isset($_COOKIE['totalCount'])) { $CookInc = $_COOKIE['totalCount'] + 1; } else { $CookInc = 1; } setcookie('totalCount', $CookInc, time()+86400); I think $_COOKIE['totalCount']++ doesn't work...anyone knows why?? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.