Solved

disable refresh for page

Posted on 2003-11-20
6
2,125 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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
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…
The viewer will learn how to count occurrences of each item in an array.
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…

758 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

17 Experts available now in Live!

Get 1:1 Help Now