<?php
$hitsfile = "counter.dat"; // The file we will use to store the number of hits
if(file_exists($hitsfile)) { // See if the counter file exists already
$exist_file = fopen($hitsfile, "r"); // File exists so lets open it
$new_count = fgets($exist_file, 255); // Gets the current content of the file
$new_count++; // Adds 1 to the variable
fclose($exist_file); // Close the file
print($new_count); // Display the number of hits
$exist_count = fopen($hitsfile, "w"); // Open the file with the Write permission
fputs($exist_count, $new_count); // Writes the new value (new number of hits_
fclose($exist_count); // Close the file
} else {
// The file doesn't exist, so lets make one
$new_file = fopen($hitsfile, "w"); // Opening the file with the Write permission will create the file
fputs($new_file, "1"); // The number of hits in this case will be 1
print("1"); // Show the current hits
fclose($new_file); // Close the file
}
?>