PHP 簡易訪問量限制程式,每個頁面總共可訪問 300 次,超過後跳轉至另一頁。
<?php
$counter_fname = 'counter.txt';
if (!file_exists($counter_fname)) {
file_put_contents($counter_fname, "300");
}
$counter = file_get_contents($counter_fname);
$counter -= 0;
if ($counter == 0) {
header("Location: https://www.example.com");
}
$counter--;
if ($fp = fopen($counter_fname, 'w')) {
fputs($fp, $counter);
fclose($fp);
}
echo "document.write('$counter');";
?>