-3

我无法让这个简单的 PHP 计数器工作。

我已将文件chmod的权限修改为.hits.txt777

我尝试将以下代码添加到我的 index.html 中,我还尝试将其用作单独的 php 文件并使用include.

<?php

$open  = fopen(“hits.txt”, “r+”);
$value = fgets($open);
$close = fclose($open);

$value++;

$open = fopen(“hits.txt”, “w+”);
fwrite($open, $value); // variable is not restated, bug fixed.
$close = fclose($open);

?>

然后在我希望显示结果的地方,我有:

<?php echo $value; ?>
4

1 回答 1

2

使用文件作为保存点的基本计数器

脚本调用myscript.php

<?php
$count = file_get_contents("/path/to/myscript_php_counter_file.txt");
$count++;
file_put_contents("/path/to/myscript_php_counter_file.txt",$count);

//rest of script here.
于 2013-09-22T01:13:11.233 回答