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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.