2010-03-11 175 views
0

在我的PHP頁面我有:PHP秒倒計時

<?php 
setcookie("game", "GOW2", time()+3); 
echo $_COOKIE["game"]."</br>"; 

echo "<a href=\"/mypro/mypro2.php/\">Refresh</a></br>"; 

?> 

現在我想在頁面加載或當用戶點擊「刷新」了以下功能

計時器應該得到重置然後顯示(作爲倒計數),並且這個倒計數直到它達到0並停止。

這是可以做到的嗎?

+1

通過一些JavaScript函數 - 當然。順便說一下,我懷疑這樣的cookie對任何事情都是有用的 – 2010-03-11 06:26:08

回答

0

你好,

在這種情況下,我會使用SESSION,而不是COOKIE。做同樣的,但會議。

<?php 
session_start(); 
if (!isset($_SESSION["game"])){ 
    $_SESSION["game"] = time()+3;//+3 is the time to the end of countdown 
} 
//get the moment of execution the script 
$now = time(); 
//calculate count down value 
$countdownvalue = $now - $_SESSION["game"]; 
//display $countdown value 
echo $countdownvalue."</br>"; 
echo "<a href=\"/mypro/mypro2.php/\">Refresh</a></br>"; 
?>