Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Dont resend data on refresh

Posted on 2004-04-13
11
Medium Priority
?
985 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
  • 2
  • 2
  • 2
  • +2
8 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 2000 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
Independent Software Vendors: 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

877 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