// Define the file to store the counter $counterFile = 'counter.txt'; // Check if the file exists, if not create it and initialize the counter to 0 if (!file_exists($counterFile)) { file_put_contents($counterFile, 0); } // Read the current counter value $currentCount = (int)file_get_contents($counterFile); // Increment the counter $currentCount++; // Write the updated count back to the file file_put_contents($counterFile, $currentCount); // Display the count on the page echo "<h2>" . $currentCount . "</h2>";