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

disable refresh for page

Posted on 2003-11-20
6
2,129 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

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