note 60081 deleted from function.file by bjori

From: Date: Wed, 22 Mar 2006 13:46:10 +0000
Subject: note 60081 deleted from function.file by bjori
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-106247@lists.php.net to get a copy of this message
Note Submitter: brunosermeus at gmail dot com ---- I've creates this function to have my own hitcounter on my site; the function writes to a file and returns the value. Created by Mr.B <?php function hitcount() { $file = "counter.txt"; if ( !file_exists($file)){ touch ($file); $handle = fopen ($file, 'r+'); // Let's open for read and write $count = 0; } else{ $handle = fopen ($file, 'r+'); // Let's open for read and write $count = fread ($handle, filesize ($file)); settype ($count,"integer"); } rewind ($handle); // Go back to the beginning /* * Note that we don't have problems with 9 being fewer characters than * 10 because we are always incrementing, so we will always write at * least as many characters as we read **/ fwrite ($handle, ++$count); // Don't forget to increment the counter fclose ($handle); // Done return $count; } ?>

« previous php.notes (#106247) next »