[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Display posted variables

Posted on 2004-10-17
4
Medium Priority
?
775 Views
Last Modified: 2012-06-21
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
Comment
Question by:ncw
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 12

Assisted Solution

by:minichicken
minichicken earned 200 total points
ID: 12331612
print_r ($_POST); //list all POST vars in an array
print_r ($_GET); //list all GET vars in an array
0
 
LVL 27

Assisted Solution

by:Diablo84
Diablo84 earned 200 total points
ID: 12331692
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
 
LVL 1

Accepted Solution

by:
milkmon123 earned 200 total points
ID: 12332769
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
 
LVL 1

Author Comment

by:ncw
ID: 12334609
Thanks everyone for commenting, I used milkmon123's example.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question