dongli5785 2013-08-14 05:31
浏览 34

页面视图计数功能给出错误的结果

I have placed a function at the end of my webpage to count the views of the thread, the function is as follows

function add_view($thread_id)
{
   global $connection;

   $qry  =  "UPDATE tbl_threads SET views = (views+1) WHERE ";
   $qry .= "thread_id= {$thread_id}";

   mysqli_query($connection,$qry,MYSQLI_STORE_RESULT);
}

This Function is triggered once at the end of the page. But the problem is When I open the page once, and then see in the database there are 4 views.

Some times it adds 3, some times it adds 4 and some times it adds 2 to the view field of tbl_threads.

It looks that my webpage triggered more than once, Is it Possible, (My webpage has Google Analytics and Google Adsense Codes also)

Can Any one analyse the problem ??

What is the solution of this Problem??

  • 写回答

2条回答 默认 最新

  • dsdfd2322 2013-08-14 05:37
    关注

    If you use url rewriting, it is possible that the browser requests additional assets (for example favicon.ico) and if that does not exist and gets rewritten to request your php file, you get another hit. Apple devices are also looking for different icons / images.

    评论

报告相同问题?

悬赏问题

  • ¥50 potsgresql15备份问题
  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上