I build websites for a lot of people, and many of them want statistics and hit counters for their websites.

Since not all of them are on a dedicated or virtual host, I cobbled together a script that builds log files, and displays a graphical hit counter, and another script that runs Webalizer and goes to the report.

My dilemma is that the hit counter portion of the script works at first, then at some point loses track, and displays a number that is way off from the actual number.

I was originally using code that read the number from a text file, added 1 to it, then wrote it back using file_get/put_contents.

Since then I have changed to

        if (file_exists($logfile)) {
                $fp = fopen("$logfile", "r+");
                flock($fp, 1);
                $count = fgets($fp, 4096);
                $count += 1;
                fseek($fp,0);
                fputs($fp, $count);
                flock($fp, 3);
                fclose($fp);
        } else {
                echo "Can't find file, check '\$logfile'<BR>";
        }

which I found in an example somewhere (maybe on the example code page?) but that seems to lose track as well.

The server is hosted by AIT, running Apache 1.3.34.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to