D
D
Danil Stolbov2020-05-15 14:06:04
PHP
Danil Stolbov, 2020-05-15 14:06:04

How to make a mutable cookie name?

You need to make a variable cookie name so that a unit is added to the cookie name, here is a code that shows the site visit counter, but you need to make the cookie name also change, how to do it?

setcookie("test", cook());
  setcookie("test", cook());
  echo "Счётчик посещений сайта {$_COOKIE["test"]}";
  function cook(){
    if (isset($_COOKIE["test"])) {
      $_COOKIE["test"]++;
    }else{
      $_COOKIE["test"] = 1;
    }
    return $_COOKIE["test"];
  }

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question