hi,
Am a newbie in php, Its been a quite a long time am trying for countdown timer in php , i have 5 different php pages with 5 questions each , when the user starts with the Q.No 1 the timer should start at each and every pages.Can any one please help me out to do this .

Thank you !

Hi there
If you just want to keep track of how long a guy was on a page simply use the following, at the top of your php page:

$time = time();
$_SESSION['time_started'] = $time;

Which stores the time (as a UNIX timestamp) that the page was loaded into the clients session. To read it out and compare it
with the time the next page is loaded, use the following:

$oldtime = $_SESSION['time_started'];
$newtime = time();
$difference = $newtime - $oldtime;

Now the variable "$difference" contains the amount of time the client spent on the first page in seconds. Then you can do what you want with it.

However, if you want to display the timer as a clock ticking down you will need to use a client-side scripting language like Javascript.

Hi there
If you just want to keep track of how long a guy was on a page simply use the following, at the top of your php page:

$time = time();
$_SESSION['time_started'] = $time;

Which stores the time (as a UNIX timestamp) that the page was loaded into the clients session. To read it out and compare it
with the time the next page is loaded, use the following:

$oldtime = $_SESSION['time_started'];
$newtime = time();
$difference = $newtime - $oldtime;

Now the variable "$difference" contains the amount of time the client spent on the first page in seconds. Then you can do what you want with it.

However, if you want to display the timer as a clock ticking down you will need to use a client-side scripting language like Javascript.

hi ,
thanks for turning up to help me ....actually the task is, time duration for 5 question is 45 min so when the user starts with the first question i need to display the time remaining at every pages according to user usage of time .... i tried it with javascript but i failed to track the duration for more than one page. please guide me .


Thank you !

If the time they've got left is stored in a client-side variable it will be easy to change it.

The best way would be using Javascript to display a ticking clock that every few seconds checks it's sync and updates a flatfile using ajax.. The amount of time left is found from the flatfile making it server-side.

Well keeping track of the time remaining is a simple issue to solve:
Just keep a time remaining variable in your session, eg:

$time = time();
      $_SESSION['time_started'] = $time;
      $_SESSION['time_remaining'] = 2700; //45 minutes
$oldtime = $_SESSION['time_started'];
      $newtime = time();
      $difference = $newtime - $oldtime;
      $_SESSION['time_remaining'] = $_SESSION['time_remaining'] - $difference;
      if ($_SESSION['time_remaining'] > 0)
      { 
          $_SESSION['time_started'] = $newtime; 
         //continue
      } else {
         //out of time
      }

hi guys,
Thanks for your suggestions and help , i did my task indulging java script and php , its been pleasure to join this community ..... please keep continue your good job...


Thank you !

If you are happy with the answer, please mark this thread as solved :)
Thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.