Jump to content

How to Unset $_POST[]


virken

Recommended Posts

Test:

[code]

<?php

$_POST['one'] = "This is a post included:";
$_POST['two'] = "- post two";
$_POST['three'] = "- post three";

if($_POST == true)
{
  foreach($_POST as $value){
    echo $value." ";
  }
  echo "<br />";
}


$_POST['two'] = false;

if($_POST == true)
{
  foreach($_POST as $value){
    echo $value." ";
  }
  echo "<br />";
}


$_POST = false;


if($_POST == true)
{
  foreach($_POST as $value){
    echo $value." ";
  }
}
else
{
  echo "No post is set";
}

?>

[/code]

Outputs:
[quote]

This is a post included: - post two - post three
This is a post included: - post three
No post is set

[/quote]
Link to comment
https://forums.phpfreaks.com/topic/31563-how-to-unset-_post/#findComment-146344
Share on other sites

[quote author=taith link=topic=119602.msg490111#msg490111 date=1166784908]
$_POST[] vars are [u]read only[/u] you cant activly create/change/alter/delete these vars other then by a form, or by changing to a different page.
[/quote]

You can unset() them though.  Try running this piece of code and seeing how many times it echo's what you type in the field:

[code]<form method="POST">
<input type="text" name="vartest">
<input type="submit" name="submit">
</form>

<?php
echo $_POST['vartest'];
unset($_POST['vartest']);
echo $_POST['vartest'];
?>[/code]

Regards
Huggie
Link to comment
https://forums.phpfreaks.com/topic/31563-how-to-unset-_post/#findComment-146345
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.