News for hackers. Stuff that matters.
Re:PHP: The Right Way by smsm42 on Sunday July 08, 2012 @12:39AM (#4213650)
What's wrong with filtering input? If you expect a number, what's wrong with telling the user "strawberry pie" is not a valid value?
Re:PHP: The Right Way by _ikke_ on Sunday July 08, 2012 @07:38AM (#4214362)
There's a fine line between filtering and validating. What's meant with filtering is things like add_slashes and mysql_real_escape_string, a uniform transformation on the input, regardless of it's destination.

Validating on the other hand is checking if the values satisfy the expected requirements.

You only want to apply certain filters if you know they apply the current output. (htmlentities if output as html, mysql_real_escape_string if embedded in a query).

Re:PHP: The Right Way by smsm42 on Monday July 09, 2012 @04:19AM (#4217201)
Filtering can't be done "regardless of destination", of course, since kind of filtering depends on the required result. Otherwise, difference between filtering and validation is largely in application semantics - some may prefer one, some another. Output is different things, of course filters can be applied to the output too.
Re:PHP: The Right Way by wilmoore on Monday July 09, 2012 @04:23PM (#4220194)
What everyone is missing with the filtering argument is:

(1) normalization (things like trim, etc. so you don't do stupid things like invalidate an email address just because it was input with trailing spaces). The result is passed to a validator.

(2) validation (if a number is expected, it's only valid if given a sequence of digits within the correct range). Valid values are passed on to the next phase (likely persisted).

Sanitization is generally not needed and in most cases likely to cause data corruption. I'm sure there are use cases for it but it should be the exception, not the rule.