<?php
$counterFile = './counter.txt';
##// Check if the counter file exists
if (file_exists($counterFile)) {
// Read the current counter value
$counter = file_get_contents($counterFile);
// Increase The value of the counter
$counter ;
} else {
// The initial counter is 1
$counter = 1;
}
//Write the new counter value to the file
file_put_contents($counterFile, $counter);
// Output the current number of visits
echo 'Website visits:' . $counter;
?>
After I added the above code to the homepage, the number increased every time the website was refreshed was not 1 but 3. For example, the first time it was 1, the next refresh would be 4, then 7, 10, 13, 16..., is there any master? Any idea where the problem is?