The Little Guy Posted June 29, 2007 Share Posted June 29, 2007 does unset() work on $_POST? Quote Link to comment Share on other sites More sharing options...
DaveLinger Posted June 29, 2007 Share Posted June 29, 2007 I would assume so, if you did unset($_POST['value']). Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted June 29, 2007 Author Share Posted June 29, 2007 but could I do unset($_POST); to unset the entire post array? Quote Link to comment Share on other sites More sharing options...
corbin Posted June 29, 2007 Share Posted June 29, 2007 $test = $_POST['test']; unset($test); echo $test; //this would always echo nothing (and if you were reporting notices, this would flag a notice) When you unset a post variable (or the entire array), PHP forgets it, but if the user refreshes their page, it will still show the "Do you wish to resend post data?" promt because PHP can not modifiy the headers the client is sending (in this case the post data from a form). I hope that made sense >.<. Quote Link to comment Share on other sites More sharing options...
DaveLinger Posted June 29, 2007 Share Posted June 29, 2007 $test = $_POST['test']; unset($test); echo $test; //this would always echo nothing (and if you were reporting notices, this would flag a notice) When you unset a post variable (or the entire array), PHP forgets it, but if the user refreshes their page, it will still show the "Do you wish to resend post data?" promt because PHP can not modifiy the headers the client is sending (in this case the post data from a form). I hope that made sense >.<. But $_POST['test'] is still set in your example, just not $test. I do not think that unset($_POST) would work, but you could do a loop to unset each POST value. Quote Link to comment Share on other sites More sharing options...
corbin Posted June 29, 2007 Share Posted June 29, 2007 Oh yeah.... I don't know why I assigned that to a variable.... The way I understand it, the $_POST array is treated as a normal (well, it's global, but you know what I mean) variable after it's defined. So if it was $test &= or if the unset was striaght on the $_POST value I think it would still do the same thing.... Gimme a sec, and I'll test something really quick. Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted June 29, 2007 Author Share Posted June 29, 2007 Like so? foreach($_POST as $val){ unset($val); } Quote Link to comment Share on other sites More sharing options...
DaveLinger Posted June 29, 2007 Share Posted June 29, 2007 function unset_posts() { foreach ($_POST as $key) { unset($_POST[$key]); } } unset_posts(); Maybe? Edit: d'oh - beaten with a better method. Quote Link to comment Share on other sites More sharing options...
corbin Posted June 29, 2007 Share Posted June 29, 2007 If you can unset each key you can unset the entire array.... Anyway, decided to test this even though I still don't see a reason why you would want to unset the POST array: <?php //the output after submitting the form /* <form method="POST" action=""> <input type="text" name="text" value="Here's some text!" /><br /> <input type="submit" /> </form> */ unset($_POST); print_r($_POST); ?> <form method="POST" action=""> <input type="text" name="text" value="Here's some text!" /><br /> <input type="submit" /> </form> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.