Jump to content

Cookie incrementing?


Tjorriemorrie

Recommended Posts

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 :(

Link to comment
https://forums.phpfreaks.com/topic/106937-cookie-incrementing/
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/106937-cookie-incrementing/#findComment-550643
Share on other sites

[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??

Link to comment
https://forums.phpfreaks.com/topic/106937-cookie-incrementing/#findComment-550662
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.