View Full Version : session countdown timer

07-04-2005, 02:59 AM
I am new to php, sorry if this question has already been answered somewhere else. I want to develope an online experiment and would like to have a time limit on how long a user has to complete the session. I would also need to display a timer on each of the page, and when the time runs out it should force the user to submit what he has. I can use javascript for the timer but not sure how I will store the remaining time on the server across page and still have javascript display it correctly on the nest page.

Thanks a lot to whoever maybe able to help me with this.

SeeIT Solutions
07-04-2005, 03:11 AM
have it store the logon time in the database you have the login details stored in and then pass that variable to a JS script that shows the remaining time until it expires.

07-04-2005, 04:22 AM
Well since it sounds like you're using form submission to navigate from page to page, why not have the timer add itself to a hidden field in the form and send it to the next page that way? Of course, it's not very secure and people could easily spoof it, but then if that's an issue for you you're unlikely to find the answer using a forms/javascript/php solution - a java applet or something might be a better way.

07-04-2005, 09:58 PM
Thanks for your help. I tried using the $_SESSION variable to pass the remaining time to and from the java script in each page, here is what I have:

<form name="Tick">
<input type="text" size="11" name="Clock">
if (!isset($_SESSION["minutes"]) && !isset($_SESSION["seconds"]))
$_SESSION["minutes"] = 12;
$_SESSION["seconds"] = 0;

<script type="text/javascript">
var minutes = $_SESSION["minutes"];
var seconds = $_SESSION["seconds"];

function display() {
if (seconds==0) {
minutes = minutes-1;

if (seconds<10)
$_SESSION["minutes"] = minutes;
$_SESSION["seconds"] = seconds;

I am new to this so I think it is something stupide I am doing it wrong here, thanks for pointing out my mistakes.