,因爲Web是無狀態,即腳本不記得任何事頁/形式執行receiver
腳本不從上次記得了最後一次它運行的時間。
但不要恐慌,有一種方法。它被稱爲SESSION,您可以將數據存儲在會話中,然後在該用戶下次連接到您的網站時可用。在PHP中,你可以像這樣使用它。會話鏈接到特定用戶的特定連接。
receiver.php
<?php
// must be run at top of script, before any output is sent to the new form
session_start();
// did the form get posted and is the variable present
// or replace POST with GET if you are using an anchor to run the script
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['val']) {
if (isset($_SESSION['limit']){
// increment the limit
$_SESSION['limit'] += (int)$_POST['val'];
} else {
// initialize the limit
$_SESSION['limit'] = (int)$_POST['val'];
}
echo 'Current value of limit is = ' $_SESSION['limit'];
} else {
// something is not right
// direct this user to some basic page like the homepage or a login
header('Location: index.php');
}
您需要存儲'$ limit'的前一個值(sessnion,cookie,DB)end將其與發件人進行標識,然後進行數學運算:) –