Posted 17 May 2006 - 03:39 PM
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?
Posted 17 May 2006 - 03:49 PM
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.
I do not always test the code I provide, so there may be some syntax errors. In 99% of all cases I found the solution to your problem here: http://www.php.net
Posted 17 May 2006 - 04:20 PM
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?
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users