Solved

Dont resend data on refresh

Posted on 2004-04-13
11
976 Views
Last Modified: 2013-12-12
Can someone tell me how to prevent data being "re-posted" when a page is refreshed.

Thanks
0
Comment
Question by:Kevin_R
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +2
11 Comments
 

Expert Comment

by:farhadabas
ID: 10817913
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
 
LVL 14

Accepted Solution

by:
ThG earned 500 total points
ID: 10818277
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
 

Expert Comment

by:farhadabas
ID: 10818634
oops sorry i didnt get your question
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 33

Expert Comment

by:snoyes_jw
ID: 10818745
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
 

Expert Comment

by:SimianStar
ID: 10855502
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
 
LVL 20

Expert Comment

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

WASIF
0
 
LVL 14

Expert Comment

by:ThG
ID: 11132565
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
 
LVL 20

Expert Comment

by:Muhammad Wasif
ID: 11132581
Today i was just looking some old questions. It definetly increase my knowledge.

WASIF
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

615 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question