php访问计数器cookie不工作为什么?

时间:2016-04-09 14:53:16

标签: php cookies counter

伙计这是我使用php cookie设置访问计数器的代码,但计数器在第一次访问后不会增加!意味着它不会超越' 1'。帮助!

<?php

    ob_start();

    error_reporting(E_ALL);
    ini_set("display_errors", "On");        

    function saveCookie($name='cookie', $val='', $time=0) {
        if ($time == 0) {
            setcookie($name, $val, 0, "/");
        }     else     {
            setcookie($name, $val, time() + ($time*1000*60*60*24), "/");            
        }
    }
    function clearCookie($name='cookie') {
        setcookie($name, '', -1, "/");
    }


   $countVisit = ($_COOKIE["countVisit"]) ? $_COOKIE["countVisit"] : 0;

   if (!isset($_COOKIE["countVisit"]))
   {
      saveCookie("countVisit",1,1);
      echo "WELCOME !";
   }
  else{
        $_COOKIE["countVisit"]++;
   }

    echo "You've visited " . $countVisit . " number of times";

 // saveCookie("countVisit",$countVisit,30);

?>

0 个答案:

没有答案