What is the difference between sanitizers and validators in PHP

Asked

Viewed 67 times

4

What’s the difference between FILTER_VALIDATE And FILTER_SANITIZE, in PHP.

1 answer

7


As the name says, FILTER_SANITIZE cleans the data by removing unwanted characters according to the criteria of that chosen sanitization, but it does not indicate whether it is valid or not. He moves the die.

Already FILTER_VALIDATE validates whether the data is valid or not, according to the criteria of that validation chosen. It responds as is the data.

In many cases both should be used, but it depends on what you want. Since sanitization does not guarantee validity, the former should be followed by the latter to ensure that it is clean and valid.

The validation should only be used if you only need a "yes or no" because even valid the data may not be completely clean (although it usually happens).

Browser other questions tagged

You are not signed in. Login or sign up in order to post.