Jump to content

How to see what is in $_POST array?


TomTees

Recommended Posts

There nothing special about the $_POST variables. You can write your own values to them, so you don't have to do 1, 2, or 3 in your list if you don't want to.

 

If you are going to be making multiple references to a variable during specific processing of it, it does save a little typing to make a copy of a $_POST variable into a regular program viable.

 

However, be careful of any use of variable variables or extract to blindly create program variables from ALL the $_POST variables as that will allow a hacker to set any of your existing program variables to any value he wants, so it is possible to screw up the execution of your code. If you use variable variables/extract like this, you should always prepend a prefix name to the variables so that they cannot overwrite any of your existing program variables.

 

 

There nothing special about the $_POST variables. You can write your own values to them, so you don't have to do 1, 2, or 3 in your list if you don't want to.

 

If you are going to be making multiple references to a variable during specific processing of it, it does save a little typing to make a copy of a $_POST variable into a regular program viable.

 

However, be careful of any use of variable variables or extract to blindly create program variables from ALL the $_POST variables as that will allow a hacker to set any of your existing program variables to any value he wants, so it is possible to screw up the execution of your code. If you use variable variables/extract like this, you should always prepend a prefix name to the variables so that they cannot overwrite any of your existing program variables.

 

So let's assume I want/need my own variables.

 

Is it better to define variables in advance in my class, and then just map the $_POST variables to my variables?

 

Or should I create my variables and my variables' values on the fly?

 

And how much better is defining my own array?

 

Because I am a procedural programmer by nature, I would usually just do:

 

 

    $email = $_POST['email'];

    $password = $_POST['password'];

    $firstName = $_POST['firstName'];

    $lastName = $_POST['lastName'];

 

But if I wanted to use an approach that could be re-used, then maybe dynamically creating variable names or using my own array is more flexible?

 

 

 

TomTees

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.