PHP 計數器,使用檔案讀寫的方式實作。
counter.php:
<?php
$pt = @fopen("log","r");
if( $pt ){
$size = filesize("log")==0?1:filesize("log");
$num = fread($pt,$size);
fclose($pt);
if( !is_numeric($num) ){
$num = 0;
}
$num++;
$pt = fopen("log","w");
fwrite($pt,$num);
fclose($pt);
}else{
$num=1;
$pt = fopen("log","w");
fwrite($pt,$num);
fclose($pt);
}
echo $num." 人次";
?>