Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP + Forms; How to prevent resending data after refreshing the page.

Status
Not open for further replies.

zWaR

Programmer
Joined
Dec 1, 2004
Messages
20
Location
SI
Hi.

I'm working on a PHP script which works together with HTML forms. And i have a problem. Everytime i push the refresh button in the browser, it asks me if i'd like to resend the data or not. If i click cancel, the page isn't refreshed and if i click resend the resended data makes nothing but mess. How to avoid resending the data?
 
You can't. You can redirect a user to another page, after the script works with POST data.

$site = "";
Header("Location: $site");
 
You can use sessions and use an integer to control if the user has already used the form.

eg.

Code:
/*####################################################
#  insert some code above here,                      #
#  which will set the session, if all input is fine  #
####################################################*/

if (!isset($_SESSION["submitted"])) {
    require("form.php");
  } // end if session is not set
else { // if session isset
    require("result.php");
  } // end if session !isset

You would also need some code inside of form.php, which validates input.

ps. this code above is not tested, except in my brain.

Olav Alexander Mjelde
Admin & Webmaster
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top