Apache/php
Fbsd1
fbsd1 at a1poweruser.com
Thu Feb 12 03:31:45 PST 2009
I have php code on home page to count how many times it is accessed from
the internet. Problem is pages deeper in website can jump back direct to
home page and this again gets counted.
Is there any way to give the php counter routine intelligent so it will
bypass bumping the counter on accesses coming from pages in the site?
I looked at the php variables but nothing jumped up that looked usable.
Am I wanting to do something that is imposable?
<?php
$counter_file = '99.00-IG_visitor_count.php';
clearstatcache();
ignore_user_abort(true); # prevent refresh from aborting file operations
$fh = fopen($counter_file, 'r+'); # use 'r+' so file can be read and
written.
if ($fh)
{
if (flock($fh, LOCK_EX)) # don't do anything unless lock is
successful
{
$count = chop(fread($fh, filesize($counter_file)));
$count++;
rewind($fh);
fwrite($fh, $count);
fflush($fh);
ftruncate($fh, ftell($fh));
flock($fh, LOCK_UN);
} else echo "Could not lock counter file '$counter_file'";
fclose($fh);
} else echo "Could not open counter file '$counter_file'";
ignore_user_abort(false); ## put things back to normal
echo "<br>
You are the $count visitor since 2/15/2009";
?>
More information about the freebsd-questions
mailing list