Solved

Display posted variables

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

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.
This article discusses how to implement server side field validation and display customized error messages to the client.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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 …

730 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