Time Delay Content by File Access Time
Beware this content is over 10 years old and considered stale. It may no longer be accurate and/or reflect the understanding of the author but remains here for reference only. Please keep this in mind as you use this content.
I was working on a mini-script to display the results of a database and then log the results into a log file. One of the problems with the logging script was that every time the page was displayed, it would pull the results from the database and log the results.
I needed a way to prevent a user from accessing the update script randomly but also needed to be able to display the update button (which linked to the update script) once a full day had passed so that the result could be manually updated in the event that they became out of date (maybe due to a failed cron job, or if a user cannot create cron jobs).
The outcome was a small script which gets the last accessed time of a file (in this case, update.php) and subtracts it from todays date and time (using the timestamp). It then determines if the resulting difference is greater or less than a certain period (in this case, 24 hours or 86400 seconds).
If the difference of time (between todays date and file) is greater than a whole day (86400 seconds) it displays the update link, because it would be good to get fresh results for that day. If, however, the time difference is less than a whole day it does not display the link or alternative content.
// time check
I will try and do a line-by-line explanation, if required but I think the script is pretty simple. If you have any points for improvement - feel free to post them here.