kaiman Posted November 16, 2009 Share Posted November 16, 2009 Hi Everyone, I currently have the following script which randomly displays a message every time a user visits/refreshes a webpage. I would like to adjust it to display a new random message every 24 hours. The problem I am having is how to get the time from the server and tell the script to update every 24 hours. Any suggestions are welcome. Thanks in advance, kaiman <?php // this script will randomly display a featured hike on each page visit // randomly displays hikes srand ((double) microtime() * 1000000); $featuredhike = rand(0,count($hike)-1); echo ($hike[$featuredhike]); // echo to page $hike[] = "<h1>Featured Hike</h1>\n<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean leo. Praesent vitae magna posuere augue iaculis scelerisque...</p>\n"; $hike[] = "<h1>Featured Hike</h1>\n<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean leo. Praesent vitae magna posuere augue iaculis scelerisque...</p>\n"; $hike[] = "<h1>Featured Hike</h1>\n<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean leo. Praesent vitae magna posuere augue iaculis scelerisque...</p>\n"; $hike[] = "<h1>Featured Hike</h1>\n<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean leo. Praesent vitae magna posuere augue iaculis scelerisque...</p>\n"; $hike[] = "<h1>Featured Hike</h1>\n<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean leo. Praesent vitae magna posuere augue iaculis scelerisque...</p>\n"; $hike[] = "<h1>Featured Hike</h1>\n<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean leo. Praesent vitae magna posuere augue iaculis scelerisque...</p>\n"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/181670-update-script-to-display-message-every-24-hours/ Share on other sites More sharing options...
mikesta707 Posted November 16, 2009 Share Posted November 16, 2009 You could just draw the featured hike from a database, and use a CRON job to update the database Quote Link to comment https://forums.phpfreaks.com/topic/181670-update-script-to-display-message-every-24-hours/#findComment-958199 Share on other sites More sharing options...
kaiman Posted November 16, 2009 Author Share Posted November 16, 2009 Thanks mikesta707, I would rather just keep in all in one file rather then quering a database. Also, I was just reading about cron jobs and it seems they can be pretty server intensive so I am reluctant to use that approach... How could I grab the server time and then use PHP operators to tell it to update itself every 24 hours? I am struggling with the logic on how to do this... Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/181670-update-script-to-display-message-every-24-hours/#findComment-958200 Share on other sites More sharing options...
kaiman Posted November 16, 2009 Author Share Posted November 16, 2009 Still looking for answers on this... Thanks, kaiman Quote Link to comment https://forums.phpfreaks.com/topic/181670-update-script-to-display-message-every-24-hours/#findComment-958265 Share on other sites More sharing options...
mikesta707 Posted November 16, 2009 Share Posted November 16, 2009 Can't really do that. PHP can get the time, and can get the time that is 24 hours from then, but you can't tell the page to execute something in 24 hours, unless you manually load the page every 24 hours. if you are only doing 1 CRON a day, (especially one that only updates 1 row of a table) you won't have to worry about server load Quote Link to comment https://forums.phpfreaks.com/topic/181670-update-script-to-display-message-every-24-hours/#findComment-958270 Share on other sites More sharing options...
kaiman Posted November 16, 2009 Author Share Posted November 16, 2009 I found this which essentially does what I want simply using PHP:http://www.phpfreaks.com/forums/index.php?topic=157119 and http://stackoverflow.com/questions/66422/how-do-i-rotate-an-image-at-12-midnight-every-day The question is how would I simply use it for the text in the file in my first post? Quote Link to comment https://forums.phpfreaks.com/topic/181670-update-script-to-display-message-every-24-hours/#findComment-958277 Share on other sites More sharing options...
kaiman Posted November 16, 2009 Author Share Posted November 16, 2009 Anybody done anything similar to this? Thanks, kaiman Quote Link to comment https://forums.phpfreaks.com/topic/181670-update-script-to-display-message-every-24-hours/#findComment-958518 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.