1
我想向用戶展示從60秒到0秒的倒計時,因爲我的腳本每60秒限制一次動作。我不需要實時更新倒計數到0
我限制了用戶訪問該頁面,但無法找到正確的方法來顯示他們何時可以下次訪問該頁面。
這是我目前有:
$sql = "SELECT * from travel WHERE username = '" . $_SESSION['user'] . "'";
$result = $dbh->query($sql);
if ($result->rowCount() == 0)
{
$sql = "SELECT name FROM countries";
$result = $dbh->query($sql);
$rows = $result->fetchAll(PDO::FETCH_ASSOC);
foreach ($rows as $row)
{
$sql = "SELECT country FROM users WHERE username = '" . $_SESSION['user'] . "'";
$result = $dbh->query($sql);
echo '<input type="radio" name="country" value="' . $row['name'] . '">'. $row['name'];
$obj = new travel($_SESSION['user']);
echo " ($" . $obj->calcCost($row['name']) .")";
echo '<br />';
}
echo '
<button type="submit" name="submit" value="Travel" />Travel</button>
<div class="spacer">
</form>';
}
else
{
$row = $result->fetch(PDO::FETCH_ASSOC);
$time_left = time()-60;
$seconds = 60;
echo "You can access this page in " . date("G:i:s", $seconds); // static value at the moment
$del = "DELETE FROM travel WHERE time_left<$time_left";
$res = $dbh->prepare($del);
$res->execute();
}
你想要一個真正的倒計時或只是說60秒,當你刷新它說別的東西。 – putvande
只需更新每個頁面上的剩餘時間即可重新加載 – user3364944
您可以爲上次加載時間()設置一個會話密鑰,並計算當前的舊會話密鑰(如果它低於60,則顯示等待消息,否則請執行您想要完成的操作。) PS將它存儲在數據庫中並每次獲取信息都可以做到這一點...... – Svetoslav