View Full Version : PHP Refresh at specific time
kumpe70
04-06-2010, 08:16 PM
Hey I don't even know if this is exactly possible, but what i'm trying to do is setup a page that will refresh at 12:00 pm MST every tuesday, and other times in the future that i should add. Also what i need done on that page is that if it's any time before 12:00 pm MST and after 1:00 pm MST then a certain page will be displayed. But between 12:00 pm MST and 1:00 pm MST a different page is shown or opened.
Basically the use for this is I work for a law firm and have maintained the basics of a website for my boss. I have learned and taught myself many things as they have come up, but my boss is trying to do an online radio station using blogtalkradio. What the goal is is to use shoutcast to constantly stream a radio station, then at 12:00 pm MST the page will be refreshed or directed to the live show player from blogtalkradio. Then at 1:00 pm MST it will change back to the shoutcast player. I will in the future need to be able to add other times for other hosts we have, but for now it's just the one person. I have found a script of AJAX that should have been able to do it for me, but it will not work. Any help would be appreciated. Thanks so much
bluewalrus
04-06-2010, 08:29 PM
So you don't actually need the page to refresh just to direct to a different page if the time is between 12:00 and 1 on Tuesday in MST, correct?
boogyman
04-07-2010, 01:42 AM
sounds very much like a homework assignment : /
djr33
04-07-2010, 04:35 AM
PHP cannot force the browser to do anything (after the page is loaded). You need Javascript or HTML redirects/reloads like a meta refresh. However, the only real way to make the browser refresh if it is a certain time is to use Javascript and hope the user doesn't block it. It will work for most, but not all visitors.
You could also use PHP to setup a meta refresh with the current number of seconds until 12:00. That's possible, and a creative way to get around the "changing" time, since for each page load it will be consistent and you can determine the number with PHP.
Of course serving a different page at a different time is easy enough-- just look at the page on php.net for the function date().
kumpe70
04-07-2010, 03:00 PM
Yes i only need a different page to be directed to between twelve and one. That way if a user is already on the page at say 11:59 the page will be redirected at noon. But if a user comes on at 12:05 they will be given the correct page. Then at one it goes back to the other page that will be displayed the majority of the time. It really doesn't matter to me how it is done, as long as i can get it done. I've been searching around on google and have been messing with different codes etc for almost a month now. Below is a link to the only post/solution i have found that seemed like it would do exactly what i want, but i cannot get it to work.
http://www.webdesignforums.net/javascript_ajax_and_json_6/refresh_page_at_specific_time_of_day_33744.html
bluewalrus
04-07-2010, 04:12 PM
Don't have time to do full code right now but what you need to do is...
Make a conditional statement that checks if the time is between 12:00 and 1
if it is between 12 and 1 then transfer them with a link to the page or header location
else echo the time the server has to javascript and let javascript redirect them if they are still on the page at 12
I think that would do it
kumpe70
04-08-2010, 03:07 PM
I've got the conditional statements set up. I am having trouble getting it to echo back to js. Any help would be appreciated. That is where I keep getting stuck.
djr33
04-08-2010, 07:17 PM
echo the number of seconds before the next change.
<script ...> var timeuntil = <?php echo $timeuntil; ?>; </script>
heavensgate15
04-09-2010, 01:30 PM
Isn't it, we still need to refresh the page so that the variable time that you set up will be updated by the time of your computer? correct me if I'm wrong. I think, we need threading? But, dunno if there is threading in php or in javascript... well, I'm still a newbie..
djr33
04-09-2010, 03:20 PM
Note: I forgot "echo" in my code above. It's now fixed.
PHP will tell Javascript a LENGTH of time. Then Javascript will do a loop (or other method) UNTIL that length of time is over.
In other words:
1. PHP generates the page saying it's 15 minutes until time to refresh.
2. Javascript saves that 15 minutes to a variable and every minute it subtracts a minute. (or more likely every second subtracts a second)
3. When that value is equal to 0, Javascript reloads the page.
setTimeOut() and other similar functions in Javascript might be more efficient in this sense, but the idea is the same.
I think this is an unusual plan because users won't like that the page randomly reloads while they are looking at it-- what if they are on a slow connection?
It might be better to have an alert popup that says "click ok to reload the page" (Actually, use a 'confirm' so that they can cancel if they don't want to).
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.