tags:

views:

28

answers:

1

in my php page i have:

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

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

?>

now i want at page load or when user clicks on 'Refresh' the following functionality

the timer should get reset and get displayed (as a countdown) and this countdown goes till it reaches 0 and stops.

is this can be done??

A: 

Hallo,

in this case I would use SESSION, not COOKIE. Make the same but wiht session.

<?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>";
?>