save this as count.php:
Code: Select all
$handle = fopen("count.txt", "r"); //r means read only
if(!$handle) { echo "could not open the file"; }
else {
$counter =(int )fread($handle,20);
fclose($handle);
$counter++;
echo"There are ". $counter . " visits so far" ;
$handle = fopen("count.txt", "w" ); //w means writing only
fwrite($handle,$counter);
fclose ($handle);
}
Then, you know, <?php include "count.php"; ?> if you want to show it on the page.
Some people will get all mad because this is using a plain text file for the log instead of using a DB, but it's simple and it works. :p


