• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1001
  • Last Modified:

Dont resend data on refresh

Can someone tell me how to prevent data being "re-posted" when a page is refreshed.

Thanks
0
Kevin_R
Asked:
Kevin_R
  • 2
  • 2
  • 2
  • +2
1 Solution
 
farhadabasCommented:
i am not sure but it might be the ur page is in the cache. try putting this ontop of ur page.


// Date in the past
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
// always modified
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
// HTTP/1.1
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
// HTTP/1.0
header("Pragma: no-cache");
0
 
ThGCommented:
Usually I play it this way,

form.html is the page containing your form.
page1.php is the page pointer to by form.html (action).
page1.php parses the data, eventually saves it to your database and generates an error code.
page1.php redirects with header("Location: page2.php?status=xxxx");
page2.php contains the user output page
0
 
farhadabasCommented:
oops sorry i didnt get your question
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
snoyes_jwCommented:
Depending on what the script does, you might find it easier to just check if it has already been posted, and then ignore it.  So, if the page inserts a record into the DB, check to see if it already exists; if not, insert as normal, otherwise ignore.
0
 
SimianStarCommented:
session_start();

$repost=1;
// CHECK ALL POSTED VARIABLES AGAINST ANY PREVIOUSLY POSTED DATA IN THE SESSION CACHE
foreach($_POST as $key => $val)
    if ( (!isset($_SESSION['POST' . $key])) OR $_SESSION['POST' . $key]!= $val)
         $repost=0;       // IF THERE IS ONE DIFFERENCE BETWEEN THE TWO DATASETS THEN IT IS NOT A REPOST

if ($repost!=1) {
    // STORE THESE POST VALUES INTO THE SESSION CACHE
    foreach($_POST as $key => $val)
        $_SESSION['POST' . $key] = $val;

   // DO WHATEVER YOU'D DO FOR FIRST TIME POSTED DATA

}
else {
 
    // HANDLE A REPOST (perhaps echo "you have already posted your data once. stop it. naughty")
}

0
 
Muhammad WasifCommented:
In my opinion the best solution is by ThG. By this way you can simplify the cade as well.

WASIF
0
 
ThGCommented:
Thank you for pointing that out wasifg. Just a curiousity.. How did you happen to open this question? You are not involved in comments..
0
 
Muhammad WasifCommented:
Today i was just looking some old questions. It definetly increase my knowledge.

WASIF
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 2
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now