Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: Page refresh

  1. #1
    Join Date
    Feb 2006
    Posts
    158
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Page refresh

    what's the simplest method of making the page refresh using PHP code?
    echo a meta refresh? echo some javascript?
    if neither of those is best, what is? and how would one script it?
    also if it is the meta refresh, how does one script that?

    thanks

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

    Default

    javascript is the worst... it is JS dependant and varies by browser. JS can also be turned off, so it's not reliable.

    Use meta:
    <meta http-equiv="refresh" content="5;url=newpage.php">

    Must be in the head section.

    Note that the 5 means five seconds... use whatever number of seconds you want, 0 for immediate.
    no quote after url, any relative or absolute url will work.

    Yeah, echo that: echo "...here...";

    The best method is to send an http header with php. That will be even better than meta. Not sure about that code, though.
    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

  3. #3
    Join Date
    Feb 2006
    Posts
    158
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Allright, great. Thanks.

    One more thing -
    When the page does reload, are all of the $_POST variables cleared?
    For example, i go from a post reply page, to my forums page. My forums page inputs the reply info using the $_Post variables, and then the page refreshes from a meta tag. Are those $_Post variables cleared on refresh?

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

    Default

    I understand the question, but I'm not quite sure.

    Have you noticed that when you are browsing and have just sent a form, then hit refresh, that it says "Warning: the page you are refreshing contains POST data. Refreshing will send it again"; or something.

    I believe it depends on the browser.

    I'm not sure if it only refreshes with post data if you do so by hitting the refresh command, rather than, for example, a meta refresh.

    However, with a meta refresh, you can specify the same URL as the current page, and it won't resend the data.

    <meta http-equiv="refresh" content="0">
    Where 0 is the time in seconds. Since the url is omitted, it's just the current page.
    That WOULD likely resend the data.
    With the example from above:
    <meta http-equiv="refresh" content="5;url=newpage.php">
    It would just be transferred to newpage.php, whether or not it was the current page, without any post data as the meta refresh is basically equivalent to an automatic link set to be "clicked" at X seconds into the page.

    Bottom line-- you can certainly insure that the data WON'T be sent again if you specify the page as a url, rather than just refreshing the current page by omitting the url attribute, but I do not know if you can guarantee that the post data WILL be sent.


    *Note: POST may be complex, but GET is very easy. If your forms use the get method, the data will be appended to the end of the URL.
    Refreshing or visiting index.php?var=val WILL resend the get data;
    refreshing or visiting index.php will NOT resend the get data.
    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
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    The POST data is never resent.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

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

    Default

    It definitely is if the user clicks refresh, at least in Safari and mozilla... not sure about IE.

    Is this disabled, then, from automatic refreshes? Only works if it's user initiated?
    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

  7. #7
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    It definitely is if the user clicks refresh, at least in Safari and mozilla... not sure about IE.
    No, the browser detects that the request required POST data and asks if the user wishes to resend it. If you use a meta refresh, the browser will simply navigate to the page to which you point it. There is no way to include POST data in the meta refresh.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  8. #8
    Join Date
    Feb 2006
    Posts
    158
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    That is good news. Thanks Twey and djr.

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

    Default

    Ok, that makes sense then.

    I know I've asked this before, but I never really got an answer, Twey. Is there any way to send the post data without sending a form?
    (I suppose one could code javascript to send a hidden form when a link is clicked... that might work)
    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

  10. #10
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    That's actually the simplest and most effective way of doing it. For a bit more flexibility, there's always AJAX, of course.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

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
  •