/    Sign up×
Community /Pin to ProfileBookmark

how to stop $_POST data from re-submitting when refreshing browser

I’m sure you’ve all encountered the pop-up alert saying

“The page you are trying to view contains POSTDATA. If you resend the data any action the form carries out will be repeated….. click ok to continue.”

Is there any way to stop this from happening? I’ve tried using the unset() method to try and erase the information in the $_POST variable, but that didn’t work.

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@SheldonOct 24.2006 — when the form is submitted and sent successfully you could set a session, and make sure that that session is not set before re-sending the form, or displaying it at all.
Copy linkTweet thisAlerts:
@SlappyTheFishOct 24.2006 — You could try something like this:

[code=php]
if ($_POST != $_SESSION['postdata'])
{
$_SESSION['postdata'] = $_POST;
}
else
{
$_SESSION['postdata'] = null;
}
[/code]


And wherever you need your post data, you just use the session variable.
Copy linkTweet thisAlerts:
@pcthugOct 24.2006 — [I]Cache-control: private[/I] means that the local browser can cache the page, but any intermediate proxies are not allowed to cache it. This should coincidently silence any unwanted [I]POSTDATA[/I] warnings.[code=php]
session_start();
@ini_set('session.cache_limiter', 'private');
@header('Cache-control: private');
[/code]
Copy linkTweet thisAlerts:
@mark_yiehauthorOct 24.2006 — Thanks everyone. I haven't learned about $_SESSIONS yet, but it seems that's what I'm going to dive into next.
×

Success!

Help @mark_yieh spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...