Jump to content

unset


The Little Guy

Recommended Posts

$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

$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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.