Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 12 Feb 2009 19:31:39 +0800
From:      Fbsd1 <fbsd1@a1poweruser.com>
To:        FreeBSD Questions <freebsd-questions@freebsd.org>
Subject:   Apache/php
Message-ID:  <4994089B.9030708@a1poweruser.com>

next in thread | raw e-mail | index | archive | help
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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;You are the $count visitor since 2/15/2009";
?>



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4994089B.9030708>