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.

 

 

Link to comment
Share on other sites

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

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.