Hi There,
I downloaded this page counter just to observe the traffic on certain pages.

Here is the code :

<?php
error_reporting(0);
$counter_name = "inc/teller/" .$StatsYear .$TellerFile;


if (file_exists($counter_name)) 
{
	$fil = fopen($counter_name, r);
	$dat = fread($fil, filesize($counter_name)); 
	fclose($fil);
	$fil = fopen($counter_name, w);
	fwrite($fil, $dat+1);
}

else
{
	$fil = fopen($counter_name, w);
	fwrite($fil, 1);
	fclose($fil);
}
?>

Now it sometimes goes back to 0, my guess is that perhaps two people at once cause the file to update and it has a fit?
It used to just make the file go blanc while it needs at least a 0 in there but I fixed that part of it with the latest version.
I added the no error code as when the file goes blanc, it used to output the error and that was annoying to say the least.

How can I stop this from happening? The counter was up to 900 something last time I looked, now it says 60 and I did not place it back to 0.
This all within the last two days.
Cheers

    I might start by changing that error_reporting(0) to something that will tell if it has any problems (such as whether or not $StatsYear and $TellerFile are actually defined?).

    <php
    ini_set('display_errors', true); // set to false in production
    error_reporting(E_ALL);
    
      17 days later
      cluelessPHP;11059593 wrote:

      Fairly sure this was the source with a few name changes ect. originally done in 2003

      http://www.pfz.nl/archief/313044-bezoekers-teller/

      Hi, that is not where I got my script from, I am sure there are many modifications out there.
      But apart from that, do you have a suggestion how to stop it going to 0 and what makes it go to 0?

        Boxkites;11059879 wrote:

        Hi, that is not where I got my script from, I am sure there are many modifications out there.
        But apart from that, do you have a suggestion how to stop it going to 0 and what makes it go to 0?

        Most likely what's happening is that there is an error reading the value from the file, and fread() returns FALSE. Since your code has no error protection, you'll then get reset to 0. If your site is high enough volume that you can have multiple people online at once, this file method will never be accurate (because even if your OS will allow multiple people to open the same file at once, the last write will just replace all the others). If this is the case, you may want to grab one of the numerous free hit counters out there. If you want very accurate, you could of course go with something like Google Analytics, which comes with a bunch of other data. If you think the file method is all you need, I would just add a basic error protection

         $dat = fread($fil, filesize($counter_name));
        if($dat !== FALSE)
        {
        fclose($fil); 
                $fil = fopen($counter_name, w); 
               fwrite($fil, $dat+1); 
        
        }
        
          11 days later

          Hi Bro,
          You Post Nice Question Regarding Counter We make one counter you can easily put anywhere in your site by just replacing some data click here to see counter code.

          It was very Helpful
          Thank You

            Write a Reply...