Page 1 of 1
Disable refresh
Posted: Thu Jul 15, 2004 3:55 am
by tores
Here's the scenario:
The user enters some data in a form, submits the data, the server stores it in the database and displays an aknowledgement.
Here's the problem:
If the user, on the aknowledgement page, refreshes the page, the data is re-sent and put once more in the database.
How can i prevent this? Is there a way to disable refreshing?
Posted: Thu Jul 15, 2004 4:35 am
by tores
Maybe one could use sessions?
if (session not set){
set session;
else{
clear entered data from database;
unset session;
echo "Refresh forbidden";
reload first page;
}
Posted: Thu Jul 15, 2004 4:50 am
by CoderGoblin
An example of another method follows
Code: Select all
<?php
if (isset($_GET['done'])) {
echo('Data saved correctly');
} else {
if (count($_POST)>0) {
// Check values and save
// if saved $saved = 1;
}
if ($saved) {
header('Location:page_name.php?done=1');
exit;
} else {
// display_errors
}
?>
This will clear the POST/GET variables from the history. OK you will have the $_GET Done left.

Posted: Thu Jul 15, 2004 8:03 am
by Bill H
I have this quite often due to popups that refresh the parent window.
I use for the input form: form.php:
Code: Select all
<form method=post action=doit.php>
<input type-text name=whatever>
</form>
And for action.php:
Code: Select all
<?php
//code to insert into database, then
header("Location:form.php");
exit;
?>
Then they can hit refresh all, they want.