unset $_POST

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
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

unset $_POST

Post by aceconcepts »

Hi All,

Using POST values are obviously submitted to the PHP engine and processed by a script. When you refresh the browser immediately after a POST it asks you whether you want to resend the POST data.

Now, is there a way to "unset" the POST request after it has been sent?

Thanks.
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: unset $_POST

Post by papa »

It doesn't work unsetting the variable?
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: unset $_POST

Post by aceconcepts »

I'm talking about erasing the complete POST array.

However, I'm rather doubtful it can be done - after all it is a method.
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: unset $_POST

Post by Eran »

The pattern I use most of the time is to redirect from the page that received the post request if it is successful (action completed). If you stay in the request (a redirect is a new request), there is no way to avoid resending the POST data on refresh.
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: unset $_POST

Post by papa »

Ok I see what you mean, sorry.
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: unset $_POST

Post by aceconcepts »

No worries Papa, i should have explained myself more clearly :D

Yes, I've had re-directs at the back of my mind. Was just wondering if there was an alternative.

Anyhow, thanks for the responses :wink:
User avatar
Syntac
Forum Contributor
Posts: 327
Joined: Sun Sep 14, 2008 7:59 pm

Re: unset $_POST

Post by Syntac »

Redirecting via header() eliminates the refresh warning.
Post Reply