<?php // PHP访客计数器 function num() { if(!file_exists("n.txt")) { $fp=fopen("n.txt","w"); fwrite($fp,"1"); fclose($fp); $n=1; } else { $fp=fopen("n.txt","r"); $n=fgets($fp); fclose($fp); $n++; $fp=fopen("n.txt","w"); fwrite($fp,$n); fclose($fp); } return $n; } ?>
本程式使用時需要上傳至對應目錄,然後在顯示訪客人數的頁面加入以下程式碼:
require_once"count.php";
$guestsnum=num();
echo"您是第".$guestsnum. "位訪客";