0

Possible Duplicate:
The ultimate clean/secure function

When it comes to sanitizing POST/GET data could we just program a loop to go through all set variables in a universal php include file and never had to worry about it in code?

I have always done a function called sanitize to do this but this seems to make sense.

Community
  • 1
  • 1
  • There is no such thing like "sanitization". Once you do something you call "sanitization" - you are doing something wrong and making your app vulnerable and/or unusable – Your Common Sense Dec 10 '11 at 22:49

2 Answers2

1

You may be better off creating a function in your application that would do it when needed. Then you'll still have the original posted values in case you need them and you can modify the function as needed based on what youre cleansing by passing it options. For example:

function getPostField($field)
{
    // all your sanitation and isset/empty checks
    $val = sanitize($_REQUEST[$field]);
    // ...
    return $val;
}
Aaron W.
  • 9,254
  • 2
  • 34
  • 45
0

Yes, of course. Some frameworks do this automatically and store the sanitized REQUEST variables in a different array or object, so the original data is still available should it ever be required.

Tak
  • 11,428
  • 5
  • 29
  • 48