Solved

disable refresh for page

Posted on 2003-11-20
6
2,126 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
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
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.

 
LVL 2

Expert Comment

by:errows
ID: 9787474
0
 
LVL 11

Accepted Solution

by:
shmert earned 500 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

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

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…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
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 count occurrences of each item in an array.

910 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

21 Experts available now in Live!

Get 1:1 Help Now