SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Addict
    Join Date
    Aug 2006
    Posts
    288
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Stop form from being resubmitted on browser reload

    What are some ways to stop a form from being re-submitted if the user reloads the browser?

  2. #2
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,788
    Mentioned
    151 Post(s)
    Tagged
    3 Thread(s)
    after you have done the processing of the form, redirect the user away to another page using header("Location: next_page.php");

    eg:
    PHP Code:
    if(isset($_POST['submitForm'])) {

    // do form processing

    header("Location: nexpage.php");
    exit(); 
    // stop the script continuing just in case

    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  3. #3
    SitePoint Addict
    Join Date
    Aug 2006
    Posts
    288
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks. But I am afraid that would create a "headers send" error in my case and I would have to change several things in order to avoid that.

    Any other solutions?

  4. #4
    SitePoint Enthusiast ivanfx's Avatar
    Join Date
    May 2007
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Use a meta refresh,

    echo "<meta http-equiv=\"refresh\" content=\"TIME_HERE;url=URL_HERE\">";

  5. #5
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,788
    Mentioned
    151 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by Zoom123 View Post
    Thanks. But I am afraid that would create a "headers send" error in my case and I would have to change several things in order to avoid that.

    Any other solutions?
    Not always, if you add ob_start(); to the top of your script it will stop the errors
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  6. #6
    SitePoint Wizard TheRedDevil's Avatar
    Join Date
    Sep 2004
    Location
    Norway
    Posts
    1,188
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    You can also just add a session variable when the form has been submitted successfully. Then on the same time check if the session variable is set before you resubmit the form.

    Then it would not matter if the same post data is resubmit, since the session variable would be set.


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
  •