Results 1 to 10 of 10

Thread: PHP Refresh at specific time

  1. #1
    Join Date
    Apr 2010
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default PHP Refresh at specific time

    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

  2. #2
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    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?
    Corrections to my coding/thoughts welcome.

  3. #3
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    sounds very much like a homework assignment : /

  4. #4
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    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().
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  5. #5
    Join Date
    Apr 2010
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    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/javas...day_33744.html

  6. #6
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    Don't have time to do full code right now but what you need to do is...

    1. Make a conditional statement that checks if the time is between 12:00 and 1
    2. if it is between 12 and 1 then transfer them with a link to the page or header location
    3. 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
    Corrections to my coding/thoughts welcome.

  7. #7
    Join Date
    Apr 2010
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    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.

  8. #8
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    echo the number of seconds before the next change.
    <script ...> var timeuntil = <?php echo $timeuntil; ?>; </script>
    Last edited by djr33; 04-09-2010 at 03:18 PM. Reason: forgot something in the code
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  9. The Following User Says Thank You to djr33 For This Useful Post:

    kumpe70 (04-13-2010)

  10. #9
    Join Date
    May 2009
    Posts
    62
    Thanks
    19
    Thanked 3 Times in 3 Posts

    Default

    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..

  11. #10
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    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).
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  12. The Following User Says Thank You to djr33 For This Useful Post:

    kumpe70 (04-13-2010)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •