The Little Guy Posted June 29, 2007 Share Posted June 29, 2007 does unset() work on $_POST? Link to comment https://forums.phpfreaks.com/topic/57644-unset/ 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']). Link to comment https://forums.phpfreaks.com/topic/57644-unset/#findComment-285406 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? Link to comment https://forums.phpfreaks.com/topic/57644-unset/#findComment-285408 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 >.<. Link to comment https://forums.phpfreaks.com/topic/57644-unset/#findComment-285409 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. Link to comment https://forums.phpfreaks.com/topic/57644-unset/#findComment-285415 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. Link to comment https://forums.phpfreaks.com/topic/57644-unset/#findComment-285420 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); } Link to comment https://forums.phpfreaks.com/topic/57644-unset/#findComment-285422 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. Link to comment https://forums.phpfreaks.com/topic/57644-unset/#findComment-285423 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> Link to comment https://forums.phpfreaks.com/topic/57644-unset/#findComment-285424 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.