|
<?php
$fp = fopen("counter.txt","r+");
// Opens the counter.txt file and "r+" sets it in read and write
modus.
flock($fp,1);
// Locks the counter file in case 2 people visit the page at the same time
$count = fgets($fp,6);
// Gets the first 6 digits from the couter file as the variable $count.
$count += 1;
rewind($fp);
fputs($fp,$count);
// Adds one to the counter and writes the updated number at start of the file.
flock($fp,3);
fclose($fp);
// locks and closes the file
echo "$count";
// writes the count on your page
?>
|