我找到了一个脚本,可以让我显示唯一身份访问者的数量,但似乎有问题。它在停止之前数了我三遍。我不擅长 PHP,但我试图找出问题所在,但无法解决。我的代码有问题吗?还有另一种更好、更简单的方法吗?
<?php
$filename = "UniqueCount.txt";
if (!file_exists($filename))
{
// hits.txt doesn't exist, let's try to create it.
$fd = fopen($filename, "w+");
fclose($fd);
}
$file = file($filename);
$file = array_unique($file);
$hits = count($file);
// Print out the number of unique visitors we have had.
echo $hits;
$fd = fopen($filename, "r");
$fstring = fread($fd, filesize($filename));
fclose($fd);
$fd = fopen($filename, "w");
$fcounted = $fstring . "
" . $_SERVER["REMOTE_ADDR"];
$fout = fwrite($fd, $fcounted);
fclose($fd);
?>
要启动,当它创建文件时。我得到错误,说
0
Warning: fread() [function.fread]: Length parameter must be greater than 0 in /home/content/46/10721146/html/UniqueHits.php on line 20
提前致谢,
精英玩家