Jump to content

Recommended Posts

I was wondering if there was a way in PHP to have a counter for 60 minutes?

Suppose I have an HTML form that when I submit it, I want the PHP to count down 60 minutes. This 60 minutes would be uniform over whoever else accesses the php files during the period. I want to be able to calculate how much time is remaining in real time, at all times.

Is this possible to do?

Thanks,
DaVuLf
Link to comment
https://forums.phpfreaks.com/topic/9861-php-countertimer/
Share on other sites

[!--quoteo(post=374692:date=May 17 2006, 10:39 AM:name=DaVuLf)--][div class=\'quotetop\']QUOTE(DaVuLf @ May 17 2006, 10:39 AM) [snapback]374692[/snapback][/div][div class=\'quotemain\'][!--quotec--]Suppose I have an HTML form that when I submit it, I want the PHP to count down 60 minutes. This 60 minutes would be uniform over whoever else accesses the php files during the period. I want to be able to calculate how much time is remaining in real time, at all times.[/quote]

Having the PHP code actually running for 60 minutes would be very inefficient and really wouldn't solve your problem. Because once a second person tries to access the PHP page it won't really matter what the first instance of the page that the first user accessed is doing. Bad design in my opinion.

The approach I would use would be to save the "last time accessed" when a user submits the form. This could be in a database or in a text file on the server. Then any page you don't want accessed in the 60 minutes should call a function at the beginning of the page and check the value of the "last time accessed". If it is less than 60 minutes before the current time then display a message to the user that they will have to wait x minutes. If the time is greater than 60 minutes then have the page continue normally.
Link to comment
https://forums.phpfreaks.com/topic/9861-php-countertimer/#findComment-36641
Share on other sites

Micheal: Thank you for the quick reply. What I'm trying to do is slightly different. I suppose it's hard to explain because most people don't use PHP or mySql for what I am doing. However, I do think that it is possible.

Now, the way this works is that depending on which minute within that 60 minute time frame is active, different numbers need to be accessed from a database. As such, I need to know which number it is (between 1 and 60) to search the database with. This means that I need this timer to apply to anyone who accesses the site during that time.

As I'm sitting here thinking about it, I suppose one could actually use a last accessed (I'm not sure how to do this, so if you could explain it that would be great) and then calculate 60 minutes based off that number. I wonder how I would translate this last accessed time into an integer format? So if I last accessed it at 5:01:32PST, then that time becomes 1, at 6:01:32PST it would be 60. Every minute between the two would have a different integer value.

Does this make more sense?
Link to comment
https://forums.phpfreaks.com/topic/9861-php-countertimer/#findComment-36654
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.