소스좀 봐주세요...24시간이 지나면 0부터 다시시작하게...하고싶은데.. 정보
소스좀 봐주세요...24시간이 지나면 0부터 다시시작하게...하고싶은데..본문
<?
function hitcount()
{
//$file_count = "count.txt";
$file_date = "./counter/count_date";
$dcount = 0;
if ( !file_exists($file_date)){
touch ($file_date);
$handle = fopen ($file_date, 'r+'); // Let's open for read and write
$dcount = 0;
}
else{
$handle = fopen ($file_date, 'rw'); // Let's open for read and write
$contents = fread($handle, filesize($file_date));
//settype ($count,"integer");
$contents = trim($contents,'|');
$content = split("\|",$contents);
$dcount = $content[0];
$omtime = $content[1];
$nmtime = date("m-d-Y", filemtime($file_date));
//echo "$count<br>$omtime<br>$nmtime";
if ($omtime != $nmtime)
$dcount = 0;
@fclose($handle);
}
//rewind ($handle); // Go back to the beginning
$contents = ++$dcount . "|" . $nmtime;// . "|";
//$contents = trim($contents,"[ |]");
$handle = fopen($file_date, 'w'); // Let's open for read and write
fwrite ($handle, $contents); // Don't forget to increment the counter
fclose ($handle); // Done
// return $count;
$file = fopen("./counter/count.txt", "r");
$count = fread($file, 1024);
fclose($file);
//Increasing the count
$count = explode("=", $count);
//$count[1] = $count[1]+1;
$count[1] = $dcount;
//Writing to file
$file = fopen("./counter/count.txt", "w+");
fwrite($file, "count=".$count[1]);
fclose($file);
//print "count=".$count[1];
}
hitcount();
?>
---------------------------------------------------------------------------------------
계속 저녁12시되면 카운트가 0으로 되서 시작하는게 아니라, 아무시간때나 자꾸 0으로 바껴서 다시 시작해 버립니다. 저녁 12시에 딱 0으로 시작하게끔 하고 싶은데... 소스에 문제가 있는거 아닌가요?어떻게 하면되나요..?;;
function hitcount()
{
//$file_count = "count.txt";
$file_date = "./counter/count_date";
$dcount = 0;
if ( !file_exists($file_date)){
touch ($file_date);
$handle = fopen ($file_date, 'r+'); // Let's open for read and write
$dcount = 0;
}
else{
$handle = fopen ($file_date, 'rw'); // Let's open for read and write
$contents = fread($handle, filesize($file_date));
//settype ($count,"integer");
$contents = trim($contents,'|');
$content = split("\|",$contents);
$dcount = $content[0];
$omtime = $content[1];
$nmtime = date("m-d-Y", filemtime($file_date));
//echo "$count<br>$omtime<br>$nmtime";
if ($omtime != $nmtime)
$dcount = 0;
@fclose($handle);
}
//rewind ($handle); // Go back to the beginning
$contents = ++$dcount . "|" . $nmtime;// . "|";
//$contents = trim($contents,"[ |]");
$handle = fopen($file_date, 'w'); // Let's open for read and write
fwrite ($handle, $contents); // Don't forget to increment the counter
fclose ($handle); // Done
// return $count;
$file = fopen("./counter/count.txt", "r");
$count = fread($file, 1024);
fclose($file);
//Increasing the count
$count = explode("=", $count);
//$count[1] = $count[1]+1;
$count[1] = $dcount;
//Writing to file
$file = fopen("./counter/count.txt", "w+");
fwrite($file, "count=".$count[1]);
fclose($file);
//print "count=".$count[1];
}
hitcount();
?>
---------------------------------------------------------------------------------------
계속 저녁12시되면 카운트가 0으로 되서 시작하는게 아니라, 아무시간때나 자꾸 0으로 바껴서 다시 시작해 버립니다. 저녁 12시에 딱 0으로 시작하게끔 하고 싶은데... 소스에 문제가 있는거 아닌가요?어떻게 하면되나요..?;;
댓글 전체
실험해보진 않았지만
$nmtime = date("m-d-Y", filemtime($file_date)); 를
$nmtime = date("m-d-Y"); 이렇게 해야 하는것 같은데요.
$nmtime = date("m-d-Y", filemtime($file_date)); 를
$nmtime = date("m-d-Y"); 이렇게 해야 하는것 같은데요.
청원님 댓글 감사하구요, 되면 바로 채택하도록 할게요.
...