working with time
Moderator: General Moderators
working with time
Hi everyone I'm looking for a way to use PhP to do time comparisons. I need it to check the current time vs a set time of 30 minutes from the time the user clicks a specific link or button. Basically it should work kind of like the following.
1)user clicks link or button timer started 30 min
2) Php periodically checks set time against current server time
3) time reached user is redirected to timeout page.
any ideas how to execute this at all?
1)user clicks link or button timer started 30 min
2) Php periodically checks set time against current server time
3) time reached user is redirected to timeout page.
any ideas how to execute this at all?
ok I understand I would need to use a session variable to accomplish this but can you define alittle more clearly how to "stamp" up on clicking. Also I've tried time comparisons and apparently I'm doing it wrong I would do something similar to this script
I set this up as a tes basically it uses mktime to set a time value of 30 minutes ahead of the current time basically making a "timestamp" like you suggested and then compares it to the current time but this always returns 0 what am I missing?
Code: Select all
$settime = mktime(0,30,0,0,0,0);
$currenttime = time();
$diff = settime - currenttime;stamp your time upon the button click:
then compare the current time to that timestamp:
Code: Select all
if(isset($_POST['buttonwhatever']))
$_SESSION['timestamp'] = time();Code: Select all
$curtime = time();
$difftime = $curtime - $_SESSION['timestamp'];
echo $difftime;Error
hmm it seems PhP is making some assumptions when it runs this code heres what the error log is reading off to me.
here is the code
$_SESSION['timestamp'] was initalized earlier as time().
Any ideas why when the page refreshes its not updating the timepast and the timeleft variables?
Code: Select all
[client 127.0.0.1] PHP Notice: Use of undefined constant curtime - assumed 'curtime' in C:\\Web\\livequiz2.php on line 55, referer: http://localhost/livequiz2.php
[client 127.0.0.1] PHP Notice: Use of undefined constant timepast - assumed 'timepast' in C:\\Web\\livequiz2.php on line 56, referer: http://localhost/livequiz2.phpCode: Select all
$curtime = time();
$timepast = curtime - $_SESSION['timestamp'];
$timepast = timepast/60;
$timeleft = 30-$timepast;
print('<P Align = "right"> Estimated Time Left ');
print $timeleft;
print(" minutes </P>");
writequestion();
print("<BR>");Any ideas why when the page refreshes its not updating the timepast and the timeleft variables?
Don't worry, happens to the best. I code in PHP for a project that I'm doing and Java for uni, interchangably. Sometimes I write $ infront of variable names in Java or declare variables in PHP (eg: int banana;).nawhaley wrote:Oy vey...I apologize for the stupidity of the previous question why I didnt notice it I dont know ..mayhaps I need more sleep :/.