• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 778
  • Last Modified:

Display posted variables

If field values are posted to another page, is there a php command to list all available variable values at the top of the page?  
0
ncw
Asked:
ncw
3 Solutions
 
minichickenCommented:
print_r ($_POST); //list all POST vars in an array
print_r ($_GET); //list all GET vars in an array
0
 
Diablo84Commented:
If this is for debugging purposes then what minichicken has said will be fine, though you might want to add pre tags so it displays in a more friendly form, eg:

echo "<pre>";
print_r ($_POST);
echo "</pre>";

however if its actually as part of your system and will be displayed to users you might want to output it in a more user friendly form, for example:

$escape = array("submit","etc"); //names of fields you dont want to display such as your submit button
foreach ($_POST as $key => $var) {
 if (!in_array($key,$escape)) echo "$var<br>\n";
}

or if you want to display the input names as well, replace:

 if (!in_array($key,$escape)) echo "$var<br>\n";

with:

 if (!in_array($key,$escape)) echo "$key: $var<br>\n";
0
 
milkmon123Commented:
print "<table>";
while (list ($key, $val) = each ($HTTP_POST_VARS)) {
      if ($key != "Submit"){
            print "<tr><td>$key</td><td>&nbsp;=&nbsp;</td><td>$val (len = ".strlen($val).")</td></tr>";
      }
}
print "</table>";

This code displays all variables passed, plus their length (in some cases, if you are processing information for use in a third party website, you may mistakenly think a string is shorter than it really is, as html will not output the spaces visibly - so the above routine tells you the length of each posted variable aswell - so you can ensure your output is correct.

Hope this helps.

Matt
0
 
ncwAuthor Commented:
Thanks everyone for commenting, I used milkmon123's example.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now