Zend - The PHP Company




Counters

Add Code


Slighty Smart text PHP Counter  

Type: code fragment
Added by: bishop
Entered: 03/03/2000
Last modified: 07/12/2003
Rating: **** (8 votes)
Views: 12047
Setup to ignore the (reload) hits. Ignores Server IP. Register Globals Safe!


<?
# author: http://modzer0.cs.uaf.edu/~bishop
# uses two files: pagehits.count and pagehits.ip
# both need to be writable by the webserver
   
$fcount fopen"pagehits.count" "rw+" );
   
$count = (int) fread$fcountfilesize"pagehits.count" ) );
   
$fip fopen"pagehits.ip" "rw+" );
   
$lastIp fread$fipfilesize"pagehits.ip" ));
# change $SERVER_ADDR to webadmin's IP to
# ignore the hits by the maintainer of the webpage.
   
if( $HTTP_SERVER_VARS["REMOTE_ADDR"] != $HTTP_SERVER_VARS['SERVER_ADDR'] )
   if( 
$HTTP_SERVER_VARS["REMOTE_ADDR"] != $lastIp      ) {
         
$count++;
         
fwrite$fcount$count);
         
fwrite$fip$HTTP_SERVER_VARS["REMOTE_ADDR"] );
   }
   
fclose($fcount);
   
fclose($fip);
#now do the not so fancy output.
   
echo $count ;
?>


Usage Example


See the example


Rate This Script





Search



This Category All Categories