Jump to content

How do you handle your POST/GET values?


9three

Recommended Posts

Hey,

 

Just curious how everyone handles their inputs when using POST/GET methods?

 

Some ways I've seen it is by just declaring them one by one:

$username = $_POST['username'];
$password = $_POST['password'];

 

Also with a for each loop like so

foreach($_POST as $key => $value)
  echo $value;

 

I'm trying to figure out if there is a more advanced/efficient way?

Link to comment
Share on other sites

I'd say it depends on what you are doing. Typically, I prefer to explicitly define variables from my post data as in your first example. I'd stay away from using something such as extract(0 to convert all the POST data into variables automatically because you can never trust user data. However, it is sometimes useful to run an automated process on all POST data, such as stripslashes() when magic quotes is on rather than checking/striping each value one at a time.

Link to comment
Share on other sites

A more advanced way would be to filter each array so that any time the array is used it is considered clean. Frameworks that I have used do this automatically, but before I started using frameworks I did the same thing. If you don't use a framework, or don't want to use a framework, you might consider downloading one just to see how it handles common tasks.

Link to comment
Share on other sites

A more advanced way would be to filter each array so that any time the array is used it is considered clean.

 

How is that different or even "more advanced" than "...to run an automated process on all POST data".

 

I was only referring to 9three's original post. You had posted before I hit the post button, and I didn't feel the need to change my post. Sorry for the confusion; we had the same idea. I usually use php's data filtering:

 

http://php.net/filter

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.