PHP TIMER FOR MULTIPLE PAGES

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
newbaba
Forum Newbie
Posts: 17
Joined: Thu Jan 26, 2017 10:36 pm
Location: Karachi

PHP TIMER FOR MULTIPLE PAGES

Post by newbaba »

need help in moving this timer through multiple pages with the elapsed time remaining from the ist page to the other pages
the Ist page code is thanks in advance

Code: Select all


<?php
session_start();
{
$dateFormat = "d F Y -- g:i a";
 $targetDate = time() + (2*120);
 $actualDate = time();
 $secondsDiff = $targetDate - $actualDate;
 $remainingDay     = floor($secondsDiff/60/60/24);
 $remainingHour    = floor(($secondsDiff-($remainingDay*60*60*24))/60/60);
 $remainingMinutes = floor(($secondsDiff-($remainingDay*60*60*24)-($remainingHour*60*60))/60);
 $remainingSeconds = floor(($secondsDiff-($remainingDay*60*60*24)-($remainingHour*60*60))-($remainingMinutes*60));
 $actualDateDisplay = date($dateFormat,$actualDate);
 $targetDateDisplay = date($dateFormat,$targetDate);
}
//include "11.php";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Quiz System</title>

<script type="text/javascript">
  var days = <?php echo $remainingDay; ?>  
  var hours = <?php echo $remainingHour; ?>  
  var minutes = <?php echo $remainingMinutes; ?>  
  var seconds = <?php echo $remainingSeconds; ?> 
function setCountDown ()
{
  seconds--;
  if (seconds < 0){
      minutes--;
      seconds = 59
  }
  if (minutes < 0){
      hours--;
      minutes = 59
  }
  if (hours < 0){
      days--;
      hours = 23
  }
  document.getElementById("remain").innerHTML = days+" days, "+hours+" hours, "+minutes+" minutes, "+seconds+" seconds";
  SD=window.setTimeout( "setCountDown()", 1000 );
  if (minutes == '00' && seconds == '00') { seconds = "00"; window.clearTimeout(SD);
   		//window.alert("Time is up. Test Is Finished."); 
  		window.location = "www.devnetwork.net" 
 	} 

}

</script>
</head>
<body onload="setCountDown();">

 Start Time: <?php echo $actualDateDisplay; ?><br />
 End Time:<?php echo $targetDateDisplay; ?><br />
 <div id="remain"><?php echo "$remainingDay days, $remainingHour hours, $remainingMinutes minutes, $remainingSeconds seconds";?></div>

  <?php echo '<a href=11.php>Click here</a>';?>
</body>
</html>

User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: PHP TIMER FOR MULTIPLE PAGES

Post by Christopher »

Either pass the start time from page to page in a HTTP parameter, or store it in the Session.
(#10850)
newbaba
Forum Newbie
Posts: 17
Joined: Thu Jan 26, 2017 10:36 pm
Location: Karachi

Re: PHP TIMER FOR MULTIPLE PAGES

Post by newbaba »

on executing these through sessions i am getting these errors i know these are very basic errors but thery are driving me crazy any help is highly appreciated
errors are Notice: Undefined variable: actualDateDisplay in C:\wamp\www\1317\22.php on line 74, Notice: Undefined variable: targetDateDisplay in C:\wamp\www\1317\22.php on line 74 and so forth for every variable on declaring global nothing works

Code: Select all

<?php
session_start();
//page1

$_SESSION['$dateFormat'] =' "d F Y -- g:i a"';
 $_SESSION['$targetDate'] = 'time() + (2*120)';//Change the 25 to however many minutes you want to countdown
 $_SESSION['$actualDate'] = 'time()';
 $_SESSION['$secondsDiff'] = '$targetDate - $actualDate';
$_SESSION['remainingDay']     = 'floor($secondsDiff/60/60/24)';
 $_SESSION['remainingHour']    = 'floor(($secondsDiff-($remainingDay*60*60*24))/60/60)';
 $_SESSION['remainingMinutes'] = 'floor(($secondsDiff-($remainingDay*60*60*24)-($remainingHour*60*60))/60)';
 $_SESSION['remainingSeconds'] = 'floor(($secondsDiff-($remainingDay*60*60*24)-($remainingHour*60*60))-($remainingMinutes*60))';
$_SESSION['$actualDateDisplay'] = 'date($dateFormat,$actualDate)';
 $_SESSION['$targetDateDisplay'] = 'date($dateFormat,$targetDate)';


/*$_SESSION['$dateFormat'] =' "d F Y -- g:i a"';
 $_SESSION['$targetDate'] = 'time() + (2*120)';//Change the 25 to however many minutes you want to countdown
 $_SESSION['$actualDate'] = 'time()';
 $_SESSION['$secondsDiff'] = '$targetDate - $actualDate';*/
 /*$remainingDay     = floor($secondsDiff/60/60/24)';
 $remainingHour    = floor(($secondsDiff-($remainingDay*60*60*24))/60/60);
 $remainingMinutes = floor(($secondsDiff-($remainingDay*60*60*24)-($remainingHour*60*60))/60);
 $remainingSeconds = floor(($secondsDiff-($remainingDay*60*60*24)-($remainingHour*60*60))-($remainingMinutes*60));*/
 //$_SESSION['$actualDateDisplay'] = 'date($dateFormat,$actualDate)';
 //$_SESSION['$targetDateDisplay'] = 'date($dateFormat,$targetDate)';
 
/* header("Location: 11.php?=".$remainingDay);
header("Location: 11.php?=".$remainingHour);
header("Location: 11.php?=".$remainingMinutes);
header("Location: 11.php?=".$remainingSeconds);*/
 
 
//include "11.php";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Quiz System</title>

<script type="text/javascript">
  var days = <?php echo $remainingDay; ?>  
  var hours = <?php echo $remainingHour; ?>  
  var minutes = <?php echo $remainingMinutes; ?>  
  var seconds = <?php echo $remainingSeconds; ?> 
function setCountDown ()
{
  seconds--;
  if (seconds < 0){
      minutes--;
      seconds = 59
  }
  if (minutes < 0){
      hours--;
      minutes = 59
  }
  if (hours < 0){
      days--;
      hours = 23
  }
  document.getElementById("remain").innerHTML = days+" days, "+hours+" hours, "+minutes+" minutes, "+seconds+" seconds";
  SD=window.setTimeout( "setCountDown()", 1000 );
  if (minutes == '00' && seconds == '00') { seconds = "00"; window.clearTimeout(SD);
   		//window.alert("Time is up. Test Is Finished."); // change timeout message as required
  		window.location = "www.devnetwork.com" // Add your redirect url
 	} 

}

</script>
</head>
<body onload="setCountDown();">

 Start Time: <?php echo $actualDateDisplay; ?><br />
 End Time:<?php echo $targetDateDisplay; ?><br />
 <div id="remain"><?php echo "$remainingDay days, $remainingHour hours, $remainingMinutes minutes, $remainingSeconds seconds";?></div>

  <?php echo '<a href=11.php>Click here</a>';?>
</body>
</html>


Last edited by newbaba on Thu Mar 23, 2017 2:40 pm, edited 1 time in total.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: PHP TIMER FOR MULTIPLE PAGES

Post by Celauran »

It looks like you're already working in the global scope. Where are these variables being declared?
Post Reply