主题:[讨论]访客计数器PHP程序
访客计数器PHP程序,要求,将访客数量显示在标题栏,以下是我的程序代码,但是运行不成功,刷新页面后,计数还是为1.请各位帮我看看问题出在哪儿?"/tmp/counter.txt"文件目录在哪儿生成的呢?
<html>
<head>
<title>
<?php
$counterFile = "/tmp/counter.txt";
function displayCounter($counterFile) {
$fp = fopen($counterFile,"rw");
$num = fgets($fp,5);
$num += 1;
print "您是第 "."$num"." 位访客";
exec( "rm -rf $counterFile");
exec( "echo $num > $counterFile");
}
if (!file_exists($counterFile)) {
exec( "echo 0 > $counterFile");
}
displayCounter($counterFile);
?>
</title>
</head>
<body>
<?php
echo "访客计数器\n";
?>
</body>
</html>
<html>
<head>
<title>
<?php
$counterFile = "/tmp/counter.txt";
function displayCounter($counterFile) {
$fp = fopen($counterFile,"rw");
$num = fgets($fp,5);
$num += 1;
print "您是第 "."$num"." 位访客";
exec( "rm -rf $counterFile");
exec( "echo $num > $counterFile");
}
if (!file_exists($counterFile)) {
exec( "echo 0 > $counterFile");
}
displayCounter($counterFile);
?>
</title>
</head>
<body>
<?php
echo "访客计数器\n";
?>
</body>
</html>