Can I clear $_POST superglobal?
Hi
I wonder whether there is a way to clear the $_POST superglobal array or even set an array element to a new value.
I've got a self-referencing form where the user can enter some text and that is calling itself. I decide whether the page was initially displayed by something like this:
if ( (isset($_POST["Submit"]) == TRUE) && ($_POST["Submit"] = 'Say') )
But once the user has submitted the form, $_POST["Submit"] will still be set when the page is reloaded (without pressing the submit button).
Is there a straigtforward way to clear or somehow modify the superglobal to prevent resubmit on reload? As you might expect, unset($_POST["Submit"]) or $_POST["Submit"]='none' does not work...
Thank you in advance
Oliver.
# 1 Re: Can I clear $_POST superglobal?
If I am understanding you correctly, you seem to think that the $_post variable stays the same through several http requests, because it stays on the server. I can assure you this is incorrect, the $_post variable always holds the http post variables from the current http request.
The reason you are seeing the same value again after a reload, is most likely that the browser repeats the same http request that was used to load the page (in this case the submit from the previous page).
khp at 2007-11-10 3:58:49 >

# 3 Re: Can I clear $_POST superglobal?
i think you are reffering to the fact that some users hit the refresh button and it tries to repost the data again to page. its a common problem with blogs that refresh to the same page.... if you want to make it so that when they hit the refresh key after posting something just redirect them to that page after you have done the neccessary code.
like either with
<code here>
header( "Location: http://pageyouwanthere" );
or make a page after the post that they click a link on to get back to the page you want them to be at.
quite like many forums do.
thebee at 2007-11-10 4:00:48 >

# 4 Re: Can I clear $_POST superglobal?
unset() ( http://www.php.net/unset) $_POST['Submit'] and then use header(), that should work.
Also change:
(isset($_POST["Submit"]) == TRUE)
to
(isset($_POST["Submit"]))
Danii at 2007-11-10 4:01:51 >
