note 2783 deleted from function.fwrite by jimw
| From: | jimw@php.net | Date: | Fri, 19 Oct 2001 18:05:19 +0000 |
| Subject: | note 2783 deleted from function.fwrite by jimw | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-19177@lists.php.net to get a copy of this message | ||
Here is a hit counter function that opens a file, reads in the value, increments it and writes it
out back to the file. It doesn't do synchronization though :)
<P>
<PRE>
<?
function IncrementHitCounter($filename)
{
// $filename is the name of the file with an integer value
// The file must have global write permisions on it (chmod 666 filename)
$counterval = 0;
$fp = fopen( $filename,"r");
$counterval = fread($fp, 26 );
fclose( $fp );
$counterval = (integer)$counterval + 1;
$fp = fopen( $filename,"w+");
fwrite( $fp, $counterval, 26);
fclose( $fp );
echo "$counterval hits on this page.";
}
?>
</PRE>