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
Solved

Dont resend data on refresh

Posted on 2004-04-13
11
970 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Suggested Solutions

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
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 dynamically set the form action using jQuery.
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…

856 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