I'm trying to make a visitor counter with php that will create yy-mm-dd.txt
everyday and contain the number of visitors that day and after 12 AM it will create a new yy-mm-dd.txt
file.
As example today is 2019-06-02 so the text file will be 2019-06-02.txt
and in the next day, 2019-06-03.txt
file will be automatically created.
Here is what I tried but it is not creating new 2019-06-03.txt
file after 12 AM. It keeps the same 2019-06-02.txt
file
<?php
$date = date('Y-m-d');
$fp = fopen('dates/'.$date.'.txt', "r");
$count = fread($fp, 1024);
fclose($fp);
$count = $count + 1;
$fp = fopen('dates/'.$date.'.txt', "w");
fwrite($fp, $count);
fclose($fp);
?>
How to fix it?