php timer

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
google
Forum Newbie
Posts: 2
Joined: Mon Oct 13, 2008 10:48 am

php timer

Post by google »

hi

is there any way that i can use to create a countdown timer using php

im designing an online exam and i want to create a secure timer that counts for an hour
i dont want to use javascript in case that it's disabled by the browser



thanks
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: php timer

Post by papa »

meta (refresh) tag maybe. :)
User avatar
omniuni
Forum Regular
Posts: 738
Joined: Tue Jul 15, 2008 10:50 pm
Location: Carolina, USA

Re: php timer

Post by omniuni »

Create a session variable, and set it to the time that the exam starts. create an iFrame which uses metadata to refresh itself, say, every second, and a php script in this iFrame which reads this session variable and displays time remaining. When time runs out, set a session variable so that when they submit the form after time, the system knows not to count it. As long as they submit before the time limit, it would then grade it and give credit. You could try setting a meta refresh/redirect as stated above to automatically move the user off the page slightly after time is up, but I would still show a clock which gives more accurate indication of time remaining.

-OmniUni
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: php timer

Post by VladSun »

Use meta refresh:

Code: Select all

 
<?php
$refresh_time = $test_time - time() + $_SESSION['start_time'] > 0 ? $test_time - time() + $_SESSION['start_time'] : 0;
?>
<meta http-equiv="refresh" content="<?php echo $refresh_time; ?>;url=http://exams.com/finished.php">
and of course in your http://exams.com/finished.php check it again (in case the user has tempered the meta tag).
There are 10 types of people in this world, those who understand binary and those who don't
google
Forum Newbie
Posts: 2
Joined: Mon Oct 13, 2008 10:48 am

Re: php timer

Post by google »

thanks alot

i will try to implement what you have post and i will tell you what happends

thanks again
Post Reply