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
Solved

Display posted variables

Posted on 2004-10-17
4
771 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
4 Comments
 
LVL 12

Assisted Solution

by:minichicken
minichicken earned 50 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 50 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 50 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

808 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