php的计数器每次都会清零
程序员文章站
2022-05-29 20:44:04
...
php
$count_num=0;
if(file_exists("counter.txt"))
{
$fp=fopen("counter.txt","r");
$counter_num=fgets($fp,9);//读取前八位数字
$count_num++;
fclose($fp);
}
$fp=fopen("counter.txt","w");
fputs($fp,$count_num);
fclose($fp);
echo" hahaha $count_num hahah";
?>
$count_num=0;
if(file_exists("counter.txt"))
{
$fp=fopen("counter.txt","r");
$counter_num=fgets($fp,9);//读取前八位数字
$count_num++;
fclose($fp);
}
$fp=fopen("counter.txt","w");
fputs($fp,$count_num);
fclose($fp);
echo" hahaha $count_num hahah";
?>
这个每次显示的都是1 就算人工修改了txt也不行 php初学者 请问问题出在哪里?谢谢!!