我写的是一个统计,读取与写入。可是数据好像经常出错,不知哪里写错了。比如明明total.txt里数据是3030,可有时候再去刷新,马上又变成1,开始增加了,好奇怪。pass.txt也是经常出错。total.txt与pass.txt里面的数字为什么不能一直增加?老是会回到1再开始增加?<?php$myfile = fopen("total.txt", "r");
$total = fread($myfile,filesize("total.txt"));
fclose($myfile);
$myfile = fopen("pass.txt", "r");
$pass = fread($myfile,filesize("pass.txt"));
fclose($myfile);if($_GET['score']){
$myfile = fopen("record.txt", "a");
$ip = $_SERVER['REMOTE_ADDR'];
$time = date("Y-m-d H:i:s",time()+8*3600);
$score = $_GET['score'];
$ttime = $_GET['ttime'];
$txt = "$time,$ip,$score,$ttime\n";
if(!empty($ttime)){
fwrite($myfile, $txt);
}
fclose($myfile);
$myfile = fopen("total.txt", "w");
$total = $total + 1;
fwrite($myfile, $total);
fclose($myfile);
if($score > 59){
$myfile = fopen("pass.txt", "w");
$pass = $pass + 1;
fwrite($myfile, $pass);
fclose($myfile);
}
//echo $txt;
exit;
}
?>
$total = fread($myfile,filesize("total.txt"));
fclose($myfile);
$myfile = fopen("pass.txt", "r");
$pass = fread($myfile,filesize("pass.txt"));
fclose($myfile);if($_GET['score']){
$myfile = fopen("record.txt", "a");
$ip = $_SERVER['REMOTE_ADDR'];
$time = date("Y-m-d H:i:s",time()+8*3600);
$score = $_GET['score'];
$ttime = $_GET['ttime'];
$txt = "$time,$ip,$score,$ttime\n";
if(!empty($ttime)){
fwrite($myfile, $txt);
}
fclose($myfile);
$myfile = fopen("total.txt", "w");
$total = $total + 1;
fwrite($myfile, $total);
fclose($myfile);
if($score > 59){
$myfile = fopen("pass.txt", "w");
$pass = $pass + 1;
fwrite($myfile, $pass);
fclose($myfile);
}
//echo $txt;
exit;
}
?>
echo '<br/>';
$total = $total + 1;
echo $total;
echo '<br/>';
fwrite($myfile, $total);
fclose($myfile);