伙计这是我使用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);
?>