3 Replies Latest reply on May 18, 2010 10:02 PM by the_shocker

    PHP Hit Counter


      Hi All,


      Here is the code that I have to a hit counter on my site, the problem is I'm having issues trying to get it to stop recording the hits with each refresh, I only want the hit to be recorded AFTER the page has been closed and then reloaded, not on refresh....any ideas?....thanks in advance.


      the code I have:



      $vlog = "hits.dat";
      $fp = fopen($vlog, "r") or die("Cannot open to read $vlog!");
      flock($fp, LOCK_EX);
      $count = fgets($fp, 1024);
      $count += 1;
      flock($fp, LOCK_UN);
      echo ("<font style='color:#000000;font-size:22px;background-color:#99ff99;'>");
      echo ("$count Visitors");
      echo ("</font>");
      $fp = fopen($vlog, "w") or die("Cannot open to write to $vlog!");
      flock($fp, LOCK_EX);
      fwrite($fp, $count);
      flock($fp, LOCK_UN);