Disable refresh

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tores
Forum Contributor
Posts: 120
Joined: Fri Jun 18, 2004 3:04 am

Disable refresh

Post 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?
tores
Forum Contributor
Posts: 120
Joined: Fri Jun 18, 2004 3:04 am

Post 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;

}
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post 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. :lol:
User avatar
Bill H
DevNet Resident
Posts: 1136
Joined: Sat Jun 01, 2002 10:16 am
Location: San Diego CA
Contact:

Post 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

&lt;form method=post action=doit.php&gt;
&lt;input type-text name=whatever&gt;
&lt;/form&gt;
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.
Post Reply