Clear $_POST after processed

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Clear $_POST after processed

Post by Skara »

My problem is when I hit the back button, I get the 'you have to resubmit the post data' message box.

Can I make it so that if I hit the back button, $_POST won't be resubmitted?

e.g.
page a: fill out form -> submit
page b: back button
(popup): resubmit blah blah blah
page a: $_POST is resubmitted again
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

What you need is an intermediate page to process the data and another to display the results.

form.html includes a form that posts data to
process.php which does data validation and inserts/selects/whatever from a db then does a header("Location: "); call to
done.php which displays information on what was done or what not.

When they get to done.php and hit back, it will bring them to form.html, since they were really never at process.php (since they were redirected before anything was displayed).
Rovas
Forum Contributor
Posts: 272
Joined: Mon Aug 21, 2006 7:09 am
Location: Romania

Post by Rovas »

That' s a good ideea d3ad1ysp0rk. Also put in your page with the HTML form this code to stop the browser from caching data inputed. You could also try using GET for the second page then you won' t need the third page (done.php) that d3ad1ysp0rk suggested but only if you trust the validation done in the first page.

Code: Select all

header( "Cache-Control: no-cache, must-revalidate" );
	    header( "Pragma: no-cache" );
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Post by Skara »

Ah, ok. I was thinking that header(Location:) would still log a back button. Silly me, that would be impossible since the browser never got it. ^^;

Thanks!
Post Reply