php 檔案統計人數代碼_PHP教程

來源:互聯網
上載者:User
代碼執行個體:


php 檔案統計人數代碼


$countfile = "num.txt";
//定義計數器寫入的檔案是目前的目錄下count.txt,然後我們應當測試該檔案能否開啟
if (($fp = fopen($countfile, "r ")) == false) { //用讀寫入模式開啟檔案,若不能開啟就退出
printf ("開啟檔案 %s 失敗!",$countfile);
exit;
}
else
{
//如果檔案能夠正常開啟,就讀入檔案中的資料,假設是1
$count = fread ($fp,10);
//讀取10位元據
$count = $count 1;
fclose ($fp);
//關閉當前檔案
$fp = fopen($countfile, "w ");
//以覆蓋模式開啟檔案
fwrite ($fp,$count);
//寫入加1後的新資料
fclose ($fp);
//並關閉檔案
}

//$count轉換為圖片模式的代碼
$fp = fopen ($countfile, "r"); //以唯讀模式開啟檔案
$array_count = 1; //定義一個表示數組元素位置的變數,下面要用
while (! feof($fp)) {
$current_number = fgetc($fp);
$counter_array[$array_count] = $current_number;
$array_elements = count ($counter_array);
$array_count = $array_count 1;
}
//顯示代碼
echo ("
歡迎您,第");
for ($array_id = 1;$array_id < $array_elements; $array_id) {
echo ("");
}
echo ("位客人
");
?>


http://www.bkjia.com/PHPjc/486222.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/486222.htmlTechArticle代碼執行個體 : HTML HEAD TITLEphp 檔案統計人數代碼/TITLE /HEAD BODY ?PHP $countfile = "num.txt"; //定義計數器寫入的檔案是目前的目錄下count.txt,然後我們應...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.