Hi,
I just wrote this a couple days ago. Hope it helps.
<?
/*
class Counter
usage:
$counter = new Counter("/path/to/your/counter.txt");
$counter->addOne();
to get count:
$count = $counter->count; /* uses count from memory in object */
$count = $counter->getCount(); /* gets latest count from counter file */
*/
class Counter
{
var $count;
var $filename;
function Counter( $filename )
{
$this->filename = $filename;
$this->getCount();
}
function addOne()
{
if ( file_exists( $this->filename ) )
{
$this->count++;
$fp = fopen( $this->filename, "w" );
fwrite( $fp, $this->count );
fclose( $fp );
}
}
function getCount()
{
$file = file( $this->filename );
$this->count = $file[0];
}
}
?>