Solved

checking and displaying POST variables

Posted on 2014-02-26
2
206 Views
Last Modified: 2014-03-02
Hi;

I want to simply display my post variables in a smart way (logging-wise) and nice looking way (css) in php.

Any sample code?

Regards.
0
Comment
Question by:jazzIIIlove
[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
2 Comments
 
LVL 56

Expert Comment

by:Julian Hansen
ID: 39888370
How about
<pre>
<?php print_r($_POST);?>
</pre>

Open in new window


Not sure what you meant by logging-wise?
0
 
LVL 110

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 39888669
First you need to understand what your post variables actually are!
http://php.net/manual/en/reserved.variables.post.php

When a client makes a request to a server, the client can send request variables.  If the request is made via the POST method, PHP will helpfully gather up the request variables and put them into a superglobal array called $_POST before your script is started.  The array contains data from an external source, therefore it is assumed to be a tainted attack vector.

There are several kinds of data that can be posted to your script from HTML forms.  You can have text or hidden or password controls, textarea string(s), checkboxes and radio controls, select dropdowns with single or multiple selections, etc.  Each of these input controls may be handled a little differently.  But all of them have two important characteristics in common.  They have a name and a value.  In the $_POST array, the name becomes the associative array key and the value, if any, becomes the associated value.  The last (rightmost) key of the same name contains the prevailing value, so if you have two HTML input controls with the same name, only the last one will show up in $_POST.  Empty input controls require a little understanding.  They are present, but the null string, in the case of most form inputs, except checkbox and radio controls.  In these controls, unfired form elements are omitted from the request and you will not find the name in the $_POST array.

You might want to set up some test cases using var_dump() to print out the contents of $_POST.  Then you can set up different forms and point the forms to the action script that will show you exactly how the POST request variables are received in your script.  You can use something like this script.

<?php // demo/bounce_post.php
error_reporting(E_ALL);
date_default_timezone_set('America/Chicago');

// START A BUFFER TO CAPTURE THE BROWSER OUTPUT
ob_start();

// USE PREFORMATTING TO MAKE THE OUTPUT EASY TO READ
echo '<pre>';

// SHOW THE GET REQUEST
echo "GET: ";
var_dump($_GET);
echo PHP_EOL;

// SHOW WHAT WAS RECEIVED IN POST
echo "POST: ";
var_dump($_POST);
echo PHP_EOL;

// CAPTURE THE BUFFER
$posted_data = ob_get_clean();

// SAY THANK YOU
echo "THANK YOU " . date('r');
echo PHP_EOL;
echo $posted_data;

Open in new window

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Help with mod_substitute 18 37
Html split(text) Part2 6 21
Making Table Thru ASP Response.write 5 19
How to pass values to HTML-5 attribute dynamically? 24 45
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

749 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