Visitor Counts in PHP stopped working suddenly

独自空忆成欢 提交于 2019-12-13 07:40:45

问题


I have visitor count script on my website.

It was working well until noon (ITC), but now it is not working, also all the files of counts are now not having any text, even a single character.

My Codes:

<?php
if (file_exists('date.txt')) {     
date_default_timezone_set('Asia/Calcutta');
$cdatel = date('Y-m-d', time());

$dthandle = fopen("date.txt", "r"); //reads date
$date =  fread($dthandle,filesize("date.txt"));
fclose ($dthandle);
$tthandle = fopen("total.txt", "r"); //reads total count
$ttcounter =  fread($tthandle,filesize("total.txt"));
fclose ($tthandle);
$ttcounter++; //+1 for new count in total
$ttl = $ttcounter;
$tthandle = fopen("total.txt", "w" ); //write for total count
fwrite($tthandle,$ttcounter);
fclose ($tthandle);
if($cdatel == $date){ //checks whether date in file is same as current date
$handle = fopen("today.txt", "r"); //reads todays count
$counter =  fread($handle,filesize("today.txt"));
fclose ($handle);
$yhandle = fopen("yesterday.txt", "r"); //reads todays count
$yv =  fread($yhandle,filesize("yesterday.txt"));
fclose ($yhandle);
$counter++; //+1 for new count in todays
$tdy = $counter;
$handle = fopen("today.txt", "w" ); //write for todays count
fwrite($handle,$counter);
fclose ($handle); 
}
else{
$ttyhandle = fopen("date.txt", "w" );
fwrite($ttyhandle,$cdatel);
fclose ($ttyhandle);
$ttyhandle = fopen("today.txt", "r");
$tdycounter =  fread($ttyhandle,filesize("today.txt"));
fclose ($ttyhandle);
$zero = "0";
$tzhandle = fopen("today.txt", "w" );
fwrite($tzhandle,$zero);
fclose ($tzhandle); 
$ttyhandle = fopen("yesterday.txt", "w" );
fwrite($ttyhandle,$tdycounter);
fclose ($ttyhandle);
?>
<meta http-equiv="refresh" content="0; ./sitemap-generator.php">
<?php
}
} 
?>

来源:https://stackoverflow.com/questions/47872128/visitor-counts-in-php-stopped-working-suddenly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!