だから私はphpを学び、ウェブページのphpヒットカウンターを作ろうとしています。今、私は自分の理解に従ってこのコードを書きました。問題は、ターミナルでプログラムを実行すると、正しい答えが得られることです(出力は期待どおりです)。HTML ページでエコーを実行すると、機能しません。ここにコードがあります
<html>
<body>
<?php
#open the file (assuming this file already exists with only 0 in it)
$file = 'test.txt';
$file = fopen($file,"r");
$temp = fread($file, 1024);
fclose($file);
#save the number 0 (initial counter to $temp) and delete it)
$file = 'test.txt';
unlink($file);
#open the file (this line just creates the file to write)
$file = fopen("test.txt","w");
fclose($file);
#increase the counter by a number (10 for testing)
$temp = (int)$temp + 10;
$file=fopen("test.txt","w");
fwrite($file,"$temp \n")
fclose($file);
#the file only contains a number ($temp - the final counter)
echo "<h1>$temp<h1>"; #this outputs the correct counter in terminal but only outputs 10 on html page. ?????
?>
</body>
</html>