?
Solved

disable refresh for page

Posted on 2003-11-20
6
Medium Priority
?
2,132 Views
Last Modified: 2012-08-13
I have a site that contains an online application.  The information is contained from one page to the next using session variables.  At the end of the 4-page application, the user hits submit and the information is emailed to the staff.  The problem we're having is that many users hit refresh several times and/or back.  We wonder what is the best way to prevent this.  Im guessing it would be done server-side and this is why im posting it here.

Thanks in advance for any help you can give!!
0
Comment
Question by:elbarro
[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
6 Comments
 
LVL 1

Expert Comment

by:show_source
ID: 9785888
One way could be using get instead of post in the form.
Another is using header("Locatio:.....................") and register a session, before header, and then show different options depending on which session is registered
0
 
LVL 19

Expert Comment

by:BrianGEFF719
ID: 9786571
Just use the following code.

<?php
// 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");
?>



What this code will do is force the client to not cache the document.


Hope this helps
-Brian
0
 
LVL 2

Expert Comment

by:errows
ID: 9787467
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 11

Accepted Solution

by:
shmert earned 2000 total points
ID: 9788617
There are actually several cases you need to handle, each with its own solution.

After the user submits the final page, and error checking passes, and the email is sent, do a header() redirect, like so:
header("Location: form_completed.php");
If the user hits refresh while on this page, the form is not resubmitted.  You'll notice that the experts-exchange site does the same thing, after you submit a post.

Preventing people from using their back button and hitting the 'submit' button again is a little trickier.  Sessions are your best bet here.  After the form is completed, but before calling header(), you can set a session variable (or just a plain cookie) indicating that the form was submitted.  On page 4 of the form, check for the existence of this session variable, and show a message that the form has already been submitted.

You should also check for the existence of this session var in the processing page, in case the user clicks back and then resubmits.  Never trust the client browser, is good paranoid advice.
0
 
LVL 1

Expert Comment

by:Peter Sweeney
ID: 10332730
What you could do is when the use submits their form to your target page, the page will create a session variable, which will be like:

if($_SESSION["submit_received"])
{
// display a message saying you're already submitted your information and that you should refrain from pressing the refresh button
echo "Thank you. We have already recieved your form data. Thanks for pressing refresh";
}
else
{
// display a message saying thankyou for your form data
$_SESSION["submit_received"] = 1; // this prevents entering this argument again

#### Here you can submit your form data to a database or email ####
}
0

Featured Post

WordPress Tutorial 3: Plugins, Themes, and Widgets

The three most common changes you will make to your website involve the look (themes), the functionality (plugins), and modular elements (widgets).

In this article we will briefly define each again, and give you directions on how to install them.

Question has a verified solution.

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

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

800 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