既然用了文件来保存,又何必再用session呢?
<body>
<?
$ip=getenv("REMOTE_ADDR");
echo $REMOTE_ADDR.":".$REMOTE_PORT." ";
$filec="userscount.txt";
$fileinfo="iptime.txt";
if(file_exists($filec))
{
$arr=file($filec);
$count=(int)$arr[0];
}
else
$count=0;
$fp=fopen($filec,"w");
fputs($fp,++$count);
fclose($fp);
echo "You are the $count guest.<br>"; $timestr=date("Y-m-d D H:i:s");
echo("You visit here at $timestr.<br>");
$fp=fopen($fileinfo,"a");
fwrite($fp,$REMOTE_ADDR.":".$REMOTE_PORT."@".$timestr."\n");
fclose($fp);
?>
</body> 上述代码要对$REMOTE_*的获得进行一些修改,因为PHP4.2.*以后的版本对这些变量有改动。
<body>
<?
$ip=getenv("REMOTE_ADDR");
echo $REMOTE_ADDR.":".$REMOTE_PORT." ";
$filec="userscount.txt";
$fileinfo="iptime.txt";
if(file_exists($filec))
{
$arr=file($filec);
$count=(int)$arr[0];
}
else
$count=0;
$fp=fopen($filec,"w");
fputs($fp,++$count);
fclose($fp);
echo "You are the $count guest.<br>"; $timestr=date("Y-m-d D H:i:s");
echo("You visit here at $timestr.<br>");
$fp=fopen($fileinfo,"a");
fwrite($fp,$REMOTE_ADDR.":".$REMOTE_PORT."@".$timestr."\n");
fclose($fp);
?>
</body> 上述代码要对$REMOTE_*的获得进行一些修改,因为PHP4.2.*以后的版本对这些变量有改动。
session_start();
session_register("ip");
$ip=getenv("remote_addr");
$fs = fopen($counterFile,"r+");
把这一段里面的session_start();去掉
然后把session_register("ip");
$ip=getenv("remote_addr");顺序颠倒一下
改成 $ip=getenv("remote_addr");
session_register("ip");
呵呵