开发者

How to set php cookie counter same url?

开发者 https://www.devze.com 2023-02-05 15:12 出处:网络
$c = $_COOKIE[\"count\"]; $c++; setcookie(\"count\", $c, time() + 86400, \'/test\', \"localhost\"); echo $_COOKIE[\"count\"];
$c = $_COOKIE["count"];
$c++;
setcookie("count", $c, time() + 86400, '/test', "localhost");
echo $_COOKIE["count"];
ob_flush();
flush(); 

?>

this is problem when change url exampl开发者_JAVA技巧e

http://www.example.com/test1 count=2
http://www.example.com/test3 count=1
http://www.example.com/test2 count=7

but i would like count only same url ?


It's the way you store the $_COOKIE.

setcookie("count", $c, time() + 86400, '/', 'yoursite.com');

The cookies you were storing will belong to that page only. This will make them accessible to the whole domain by defining a folder and domain.

0

精彩评论

暂无评论...
验证码 换一张
取 消