2007/10/06

PHP counter by file IO

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." 人次";
?>

1 則留言:

  1. 我…懶得在自己電腦裝apache =____=

    回覆刪除