PX : code

Smart Counter by Jason Hines
Download this code


<?php        
    
/*
        Orig: simple access counter for php3
        (c)1998 David W. Bettis
        dbettis@eyeintegrated.com

    Modified smart counter:
      Uses cookies to determine whether or not to bump the
      count.  Cookie expires after 10 minutes.

    v1.1 Jason Hines <openface@eyeintegrated.com>
        */

$counterFile "/home/httpd/html/counter/counter.text";

function 
displayCounter($counterFile) {
        global  
$counted
        $fp     
fopen($counterFile,rw);
        
$num    fgets($fp,5);
        if (!
$counted) {
                
$num    += 1;
                
unlink("$counterFile");
                
exec("echo $num > $counterFile");
        }
        print 
"$num";
}

if (!
file_exists($counterFile)) {
        
exec("echo 1 > $counterFile");
}

displayCounter($counterFile);
?>


/* Add the following to the very top of the page you want to count */

<?php if (!$counted) { setcookie("counted",1,time()+600); } ?>

Comments or questions?
PX is running PHP 5.2.17
Thanks to Miranda Productions for hosting and bandwidth.
Use of any code from PX is at your own risk.