简体   繁体   English

PHP 计算唯一访问者,无效

[英]PHP Count Unique Visitors ,, Not Works

I am willing to count unique visitors once landing on a specific page, I wrote the below code, but the database updates each visit not uniquely,一旦登陆特定页面,我愿意计算唯一访问者,我编写了以下代码,但数据库更新每次访问不是唯一的,
tried to check the cookie in chrome settings, but did not find TestCookie尝试检查chrome设置中的cookie,但没有找到TestCookie
Then tried to check from Inspect->Network->Cookies I found my cookie in response cookies ,然后尝试从 Inspect->Network->Cookies 检查我发现我的 cookie响应 cookies
Actually, I don't know if this means that it was saved or not, because if it is saved, so why database updates each repeated visit...其实我不知道这是否意味着它被保存了,因为如果它被保存了,那么为什么数据库每次重复访问都会更新......

<?php include "db.php"; ?>
    <?php
    if(!isset($_COOKIE['TestCookie'])){
      setcookie("TestCookie","yes",60*60*24*320);
      mysqli_query($dbConnection,"UPDATE visits SET otal_count = total_count+1");
      print_r($_COOKIE);
    
    }else{
      return false;
    }
    ?>

Can you try to change third (expires_or_options) paramater of setcookie to您可以尝试将 setcookie 的第三个 (expires_or_options) 参数更改为

time() + 60*60*24*320

setcookie("TestCookie","yes",time() + 60*60*24*320);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM