Solved

Dont resend data on refresh

Posted on 2004-04-13
11
967 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
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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PHP_POST() error message 9 44
.php tree directory? 5 56
How can I echo a PHP variable in AJAX function? 7 35
PHP: Insert Data into MySQL 5 16
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

895 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now