Solved

Display posted variables

Posted on 2004-10-17
4
767 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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
spacing 5 29
how can I dected if URL has variable? 7 23
html input clean up 3 32
Strip leading 0 from a var 3 12
Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

706 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now