php time and how to keep track of it.

I want to track time in a database when i user goes to my web page and joins a clock starts.

This clock is a random time that starts anywhere between 1h and 5h from the time he first open the site. Have the timer displayed on the site as it counts down.

ones the timer runs out the user can click a button after the user clicks this button the time is reset with other random time between 1h and 5h form the users current time. This keep happening to anyone that joins the site.

I know there is a lot to do here. What i need help with is log the time in a database for each user. I already have most of that done i just don't know how to keep track of time.

1. Log user time
2. Set random time ones the user is log in between 1h and 5h form the users current time.
3. Have ajax display that time and count down in real time.

Also why is 500 the most Points i can give can't i do like 2 500s
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ray PaseurCommented:
500 points is plenty for questions like this.  If it's more than a 500 point question, hire a professional developer to save you time.   But on to the issues...

How to choose a random number of hours:

$hours = rand(1,5);

How to get the expiration time in a format suitable for inserting into a data base DATETIME column:

$expires = date('c', strtotime("NOW + $hours HOURS"));

How to show a countdown timer that will redirect after a given period of time (see code snippet).  This is not completely "valid" in HTML terms because the meta Refresh is deprecated, however the deprecation notice is very old, and the tag has not been removed from any modern browser.  In other words, it works.

Best regards, ~Ray
<?php // RAY_countdown_timer.php

$timer = '7';

<script type="text/javascript">
var interval = "";
var sekonds  = <?php echo $timer; ?>;

function startInterval()
    interval = window.setInterval("tTimer()",1000);
function stopInterval()
    window.clearInterval (interval);
function tTimer()
    document.thinkTime.tDisplay.value = sekonds--;
    if (sekonds == -1)

document.write('<meta http-equiv=\"Refresh\" content=\"<?php echo $timer; ?>;url=\">');

<form name="thinkTime">
This page will search for a JavaScript Timer in
<input readonly class="timerBox" size="1" type="text" name="tDisplay" value="">
<a href="">Click here if you don't want to wait.</a>

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mikearmasAuthor Commented:
that worked great
Ray PaseurCommented:
Thanks for the points!  All the best for the New Year, ~Ray
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.