Solved

disable refresh for page

Posted on 2003-11-20
6
2,128 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PHP installation issues 11 62
How can I change this hyperlinked phone number to be black and is it working? 2 54
php function to remove a file 31 40
PHP AJAX Wordpress 9 21
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 …
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…
The viewer will learn how to count occurrences of each item in an array.
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.

810 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