Can you empty POST data?
Moderator: General Moderators
Can you empty POST data?
At some tutorial was written you can clear POSTDATA by doing $_POST = array();
However, I tried it on different servers and at any case FF said that I still have POST data when I hit "refresh".
So maybe it's not even possible?
However, I tried it on different servers and at any case FF said that I still have POST data when I hit "refresh".
So maybe it's not even possible?
- Maugrim_The_Reaper
- DevNet Master
- Posts: 2704
- Joined: Tue Nov 02, 2004 5:43 am
- Location: Ireland
POSTDATA is not PHP's $_POST
POSTDATA is sent from the browser to the server. Code on the server will not effect the client's behaviour in that regard.
Firefox after submitting data by POST will request if you want to so again - IF you refresh the page following a form submit. Actually this is one of the reasons I use GET for requests leading to an action (despite what Google Webaccelerator advocates may swear to).
Since you are refreshing, FF takes it you may also want to submit the data again / or not. Either way you get to choose rather than leaving it up a non-sentient browser
POSTDATA is sent from the browser to the server. Code on the server will not effect the client's behaviour in that regard.
Firefox after submitting data by POST will request if you want to so again - IF you refresh the page following a form submit. Actually this is one of the reasons I use GET for requests leading to an action (despite what Google Webaccelerator advocates may swear to).
Since you are refreshing, FF takes it you may also want to submit the data again / or not. Either way you get to choose rather than leaving it up a non-sentient browser
Just use
if you want to get rid of all of the data, or
to get rid of a specific element of the array.
Edit - the browser does still hold the contents in memory though, so if the page is refreshed, it will attempt to resubmit the data. I guess the only way to clear it for good is to load a separate 'clean' page.
Code: Select all
unset($_POST)Code: Select all
unset($_POST['foo'])Edit - the browser does still hold the contents in memory though, so if the page is refreshed, it will attempt to resubmit the data. I guess the only way to clear it for good is to load a separate 'clean' page.
Last edited by BruceT on Sat Sep 24, 2005 11:17 am, edited 1 time in total.
Hmm, ok. Understood.
However, a new question had popped in front of my eyes: If I set a new element in the $_POST array, and then submit an HTML form, that is:
Will POSTDATA contain the "something" element afterwards?
However, a new question had popped in front of my eyes: If I set a new element in the $_POST array, and then submit an HTML form, that is:
Code: Select all
<?php
$_POST['something'] = "string";
print "<form action='this.file' method ='POST'>
<input type='submit'>
</form>";
?>No.pilau wrote: Will POSTDATA contain the "something" element afterwards?
To add a field to $_POST array after resubmit you have to regenerate your form with additional field(s):
Code: Select all
<?php
$_POST['something'] = "string";
print "<form action='this.file' method ='POST'>";
foreach($_POST as $key=>$val) {
print "<input type='hidden' name='$key' value='$val' />\n";
}
print "
<input type='submit'>
</form>";
?>That should be used if I want to generate the exact form I had before I refreshed the page.Weirdan wrote:Code: Select all
<?php $_POST['something'] = "string"; print "<form action='this.file' method ='POST'>"; foreach($_POST as $key=>$val) { print "<input type='hidden' name='$key' value='$val' />\n"; } print " <input type='submit'> </form>"; ?>
(Which basically I could just copy the source code from the form I made
If all you want to archive is that you cannot refresh the post data you can use sessions to disallow the refresh.
You can set a session var on the form page and only allow post data to be shown if that var is correct. After the data is shown change that var. For the cookie disabled you can use sid or tell them to enable cookies to submit the form.
You can set a session var on the form page and only allow post data to be shown if that var is correct. After the data is shown change that var. For the cookie disabled you can use sid or tell them to enable cookies to submit the form.
No, don't copy the source code.. because his example used hidden input fields. This would resubmit the former postdata along with post['something'] but be seamless to the end user.pilau wrote:That should be used if I want to generate the exact form I had before I refreshed the page.Weirdan wrote:Code: Select all
<?php $_POST['something'] = "string"; print "<form action='this.file' method ='POST'>"; foreach($_POST as $key=>$val) { print "<input type='hidden' name='$key' value='$val' />\n"; } print " <input type='submit'> </form>"; ?>
(Which basically I could just copy the source code from the form I made)
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.