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
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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.