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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to block "refresh" feature?

Status
Not open for further replies.

alan123

MIS
Joined
Oct 17, 2002
Messages
149
Location
US
I have a php page which is used to load data to mysql db, everytime when I click "submit" button it will send data out, but I have a question how to solve the issue by clicking "refresh" button on the browser, it will show the message(on IE) "The page cannot be refreshed without resending the information, click Retry to send the information again, or click Cancel to return the page that you were trying to view", is there a way to block refresh feature on browser, or I can set some parameters in the form so it won't execute when click refresh button. any help will be appreciated.
 
Preventing a form submission would require client-side scripting and would be browser specific.

Here's what I do instead.

Let's say that you have to retrieve data from a user in two parts -- on the first page the user inputs his name and on the second he inputs his address.

I would write name.php so that when it is invoked, it examines $_POST for input field names "lastname" and "firstname". If both do not exist, the script assumes that it was handed no input and produces the input form. That form's "action=" setting is name.php, so the form submits back to the script that created the form.

Should the user enter a firstname and lastname and submit the form, name.php inserts the data into either the database or a session variable, then uses header("Location:....") to redirect the browser to address.php.

Address.php words similarly to name.php. If it does not find a "street" and "city" form input in $_POST, it produces the input form. Otherwise it processes the input and uses header("Location:...") to redirect the browser to another page in the site.

With this method, the user does not stay on a page anywhere that might allow him to resubmit the data on a refresh.

It's not necessary to have the form produced by name.php submit back to itself. You would have 4 scripts, name_form.php, name_process.php, address_form.php and address_process.php. Name.php produces a form which will submit to name_process.php. Name_process.php will, if there is input, process the input and redirect to address_form.php or, if there is no input, redirect back to name_form.php. And so on.

It's also possible to have error messages sent back and forth between the various scripts using session variables.

Want the best answers? Ask the best questions: TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top