473,903 Members | 4,374 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Clearing POST DATA for Browser Refresh

PHP Pros:

I have a simple html form that submits data to a php script, which
processes it, and then redisplays the same page, but with a "thank you"
message in place of the html form. This is all working fine. However,
when refresh the browser, I get the following message displayed:

"The page you are trying to view contains POSTDATA. If you resend the
data, any action the form carried out (such as as search or online
purchse) will be repeated. To resend the data, click OK. Otherwise,
click Cancel."

Obviously I don't want my users to resend the data to me.

What do I need to do code-wise so that when the browser is refreshed,
the page is reloaded without this message being displayed.

Thanks in advance.
Feb 14 '06 #1
15 33535
tmax wrote:
PHP Pros:

I have a simple html form that submits data to a php script, which
processes it, and then redisplays the same page, but with a "thank you"
message in place of the html form. This is all working fine. However,
when refresh the browser, I get the following message displayed:

"The page you are trying to view contains POSTDATA. If you resend the
data, any action the form carried out (such as as search or online
purchse) will be repeated. To resend the data, click OK. Otherwise,
click Cancel."

Obviously I don't want my users to resend the data to me.

What do I need to do code-wise so that when the browser is refreshed,
the page is reloaded without this message being displayed.

Thanks in advance.

Don't redirect to the form; redirect to a summary page without the form
or make your form page sensitive to whether the $_POST data is available
and do not have it emit a <form> if the $_POST data is available.

I prefer the first method over the second.

-david-

Feb 14 '06 #2
d
"tmax" <tm**@comcast.n et> wrote in message
news:82******** *************** ****@PGTV.COM.. .
PHP Pros:

I have a simple html form that submits data to a php script, which
processes it, and then redisplays the same page, but with a "thank you"
message in place of the html form. This is all working fine. However,
when refresh the browser, I get the following message displayed:

"The page you are trying to view contains POSTDATA. If you resend the
data, any action the form carried out (such as as search or online
purchse) will be repeated. To resend the data, click OK. Otherwise, click
Cancel."

Obviously I don't want my users to resend the data to me.

What do I need to do code-wise so that when the browser is refreshed, the
page is reloaded without this message being displayed.

Thanks in advance.


In the script to which the form submits, store the $_POST data somewhere
else, say a session. Then, use this:

header("Locatio n: http://host/path/to/script.php");
exit();

to bounce the user to another page. Most browsers know to not re-submit the
post data to this new page. The new script can even be the originating
one - as long as you use the location: header, you'll be fine. You can then
access the submitted data wherever you stored it.

PS. if you're using a session to store the data, call session_write_c lose()
before the header() call, otherwise nasty things happen on some browsers.

dave
Feb 14 '06 #3

d wrote:
"tmax" <tm**@comcast.n et> wrote in message
news:82******** *************** ****@PGTV.COM.. .
PHP Pros:

I have a simple html form that submits data to a php script, which
processes it, and then redisplays the same page, but with a "thank you"
message in place of the html form. This is all working fine. However,
when refresh the browser, I get the following message displayed:

"The page you are trying to view contains POSTDATA. If you resend the
data, any action the form carried out (such as as search or online
purchse) will be repeated. To resend the data, click OK. Otherwise, click
Cancel."

Obviously I don't want my users to resend the data to me.

What do I need to do code-wise so that when the browser is refreshed, the
page is reloaded without this message being displayed.

Thanks in advance.


In the script to which the form submits, store the $_POST data somewhere
else, say a session. Then, use this:

header("Locatio n: http://host/path/to/script.php");
exit();

to bounce the user to another page. Most browsers know to not re-submit the
post data to this new page. The new script can even be the originating
one - as long as you use the location: header, you'll be fine. You can then
access the submitted data wherever you stored it.

PS. if you're using a session to store the data, call session_write_c lose()
before the header() call, otherwise nasty things happen on some browsers.

dave


Just curious, but is there / would you recommend a good alternative for
the Sessions?

Frizzle.

Feb 14 '06 #4
Well, I've tried everything that has been suggested so far - thanks for
everyone's input.

However, let me restate the problems differently as I believe it wasn't
correct to begin with.

I have a file: index.php

index.php contains a form, which when submitted for processing, calls
itself using <form method="POST" action="{$_SERV ER['PHP_SELF']}">

When the form is submitted and index.php is reevaluated, I have the
following IF statement: (FYI: 'submit' is the name of the submit button.)
------------
IF ( !isset($_POST['submit']) ) {
// The form has NOT been SUBMITTED - display the form

echo <<<htmloutput
<form method="POST" action="{$_SERV ER['PHP_SELF']}">
...
</form>
htmloutput;

} ELSE {
// The form was SUBMITTED - process the form

process the form data, etc. and print in PLACE of the form the
following:

echo "Informatio n submitted... Thank you.";
}
-------------

I understand I can redirect to a (different) summary page, but all I
want to do is replace the form with the summary message. The problem
comes into being when, after the summary message is displayed, the user
goes to refresh the browser. The browser is still caching the form data
for resubmission. I've tried things like: unset($_POST) or
unset($_POST['submit']) (and all the other form fields) but that has no
affect.

Any other suggestions?

Thanks in advance.

d wrote:
"tmax" <tm**@comcast.n et> wrote in message
news:82******** *************** ****@PGTV.COM.. .
PHP Pros:

I have a simple html form that submits data to a php script, which
processes it, and then redisplays the same page, but with a "thank you"
message in place of the html form. This is all working fine. However,
when refresh the browser, I get the following message displayed:

"The page you are trying to view contains POSTDATA. If you resend the
data, any action the form carried out (such as as search or online
purchse) will be repeated. To resend the data, click OK. Otherwise, click
Cancel."

Obviously I don't want my users to resend the data to me.

What do I need to do code-wise so that when the browser is refreshed, the
page is reloaded without this message being displayed.

Thanks in advance.

In the script to which the form submits, store the $_POST data somewhere
else, say a session. Then, use this:

header("Locatio n: http://host/path/to/script.php");
exit();

to bounce the user to another page. Most browsers know to not re-submit the
post data to this new page. The new script can even be the originating
one - as long as you use the location: header, you'll be fine. You can then
access the submitted data wherever you stored it.

PS. if you're using a session to store the data, call session_write_c lose()
before the header() call, otherwise nasty things happen on some browsers.

dave

Feb 14 '06 #5
I have to ask, why would you assume your users would refresh that page
rather than following a link somewhere else?

Feb 14 '06 #6
I have to ask, why would you assume your users would refresh that page
rather than following a link somewhere else?

Feb 14 '06 #7
I don't think there is another solution than storing state information
somehwere.
I would use the following method:

1. Before displaying the form, generate some unique number
2. add this number in a hidden field in the form.
3. When the user submits, mark the number as 'used'
4. When the user submits again, ignore the data, because the number
has already been 'used' up.

The simplest way to do this is to create a counter, either in a file on disk
or in
a database. Before you send the form to the client, increment the counter
and send
the counter value in a hidden field in the form.

If you save the form data in a database table, add a 'counter' field to the
table.
When the form is first submitted, a record with the counter value sent with
the form should not exist. Save data and counter.
If the form is submitted for a second or third time, the counter is already
present in
your table, so you should ignore the data in the post.

Using a session cookie is, I think, less work.
"tmax" <tm**@comcast.n et> wrote in message
news:82******** *************** ****@PGTV.COM.. .
PHP Pros:

I have a simple html form that submits data to a php script, which
processes it, and then redisplays the same page, but with a "thank you"
message in place of the html form. This is all working fine. However,
when refresh the browser, I get the following message displayed:

"The page you are trying to view contains POSTDATA. If you resend the
data, any action the form carried out (such as as search or online
purchse) will be repeated. To resend the data, click OK. Otherwise, click
Cancel."

Obviously I don't want my users to resend the data to me.

What do I need to do code-wise so that when the browser is refreshed, the
page is reloaded without this message being displayed.

Thanks in advance.

Feb 14 '06 #8

True, they could instead following some other link and decide not to
refresh the page. However, I would like the page to function such that
refreshing the page simply re-displays a new blank form (after all,
refreshing a page is conceptually akin to resetting.)

I started off on this path thinking that this format should be
relatively easy to code with one if-else statement. So far, it has been
easy to code (the form and summary message work great, with very little
coding). I keep thinking that there is some PHP mechanism that isn't
being used properly here (due to my PHP inexperience.)

Any suggestions?

P-Rage wrote:
I have to ask, why would you assume your users would refresh that page
rather than following a link somewhere else?

Feb 14 '06 #9
d
"frizzle" <ph********@gma il.com> wrote in message
news:11******** **************@ o13g2000cwo.goo glegroups.com.. .

d wrote:
"tmax" <tm**@comcast.n et> wrote in message
news:82******** *************** ****@PGTV.COM.. .
> PHP Pros:
>
> I have a simple html form that submits data to a php script, which
> processes it, and then redisplays the same page, but with a "thank you"
> message in place of the html form. This is all working fine. However,
> when refresh the browser, I get the following message displayed:
>
> "The page you are trying to view contains POSTDATA. If you resend the
> data, any action the form carried out (such as as search or online
> purchse) will be repeated. To resend the data, click OK. Otherwise,
> click
> Cancel."
>
> Obviously I don't want my users to resend the data to me.
>
> What do I need to do code-wise so that when the browser is refreshed,
> the
> page is reloaded without this message being displayed.
>
> Thanks in advance.
In the script to which the form submits, store the $_POST data somewhere
else, say a session. Then, use this:

header("Locatio n: http://host/path/to/script.php");
exit();

to bounce the user to another page. Most browsers know to not re-submit
the
post data to this new page. The new script can even be the originating
one - as long as you use the location: header, you'll be fine. You can
then
access the submitted data wherever you stored it.

PS. if you're using a session to store the data, call
session_write_c lose()
before the header() call, otherwise nasty things happen on some browsers.

dave


Just curious, but is there / would you recommend a good alternative for
the Sessions?


Databases or files spring to mind :)
Frizzle.

Feb 14 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
2724
by: brendan | last post by:
Sorry this isnt a cross post .. i just didnt get any help from alt.php. I have a website which utilises post forms for navigation in some areas. Problem is, when *some* users hit the BACK button the POSTDATA content has expired and they need to refresh the page then they get a alert about refreshing expired data. I am getting complaints that this is too annoying and limits the sites useability.
7
5668
by: milkyway | last post by:
Hello to all ;-) I am using the Visual Studio 2005 .NET framework. Basically, I have file that is served up as an HTML file on the client side (generated from a .aspx file). But - the HTML file is using javascript to implement a button click (on the client side). Ex: <INPUT onclick="alert('about to start'); process_table('FrmX1',
1
2727
by: David P. Donahue | last post by:
I have an ASP .NET website where users submit comments and, depending on whether or not the web service accepting the comments returns an error, the form uses this.page.registerstartupscript() to popup a dialog box confirming that the submission was received. It seems that, after this takes place, the resulting page still has the form data (even though the form elements have been cleared). Thus, a refresh of the page re-submits the...
1
2304
by: Dabbler | last post by:
What effect does the browser refresh button have on a) session variables and b) viewstate? My page loads info based on session variables and it seems this breaks when someone does a page refresh. Thanks for info or link to info on this. Dabbler
4
2310
by: Thomas Eichner | last post by:
Hi, does anybody know a public website which offers a service that displays all data send by a browser (or an app calling the website), especially HTTP GET and POST data, browser data etc.? I have a hard time finding what really my app is sending and this would be a great help! Thank you very much ! Thomas
2
3443
by: pingalkar | last post by:
In my application, on one form i m getting information from user and save this information , after saving this information again we loading that page. (At this moment if any one try to refresh this page, then save action will call) this should not be happen. only data will save , when we click on the save button. Why every refresh save action getting call and what is solution on this problem? Is there any javascript method available to...
8
3916
by: ninuhadida | last post by:
hi there! This is actually my first post over here.. I thought i'd register since most answers to my common problems that i google up turn up to be in this site.. however I have a problem myself now. This is the source code: (PHP) if(mysql_error()) { // was there an error ? //yes, issue warning echo "Sorry, your comment was <b>not</b> added due to a database error!"; } else { // no, print success and link echo "<meta...
6
7224
by: kiran Vidhate | last post by:
Hi I need small help, What I need is when I write a script to handle my post data on my login page. if login failed and i press refresh key browser shows msg to resend the post data I tried unset() function too, But it didn't work. Do any one have anything for me ? Thanks In advance
4
18140
by: =?Utf-8?B?QXNhZg==?= | last post by:
Hi, How can I prevent from an ASP.NET page to resend all the data again when the user press the Refresh button or F5 on the browser? Thanks in advanced, Asaf
0
9999
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
9849
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10878
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10986
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10501
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5894
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6094
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4308
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3324
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.