filter_var or filter_input?

At this moment I’m receiving the $_POST as they are, inside some setters methods. On those setters, I’m using filter_var.

My question is, on what circumstances it’s better to use filter_var and on what circumstances we are better served with filter_input ?

Thanks in advance,

So, INPUT_GET acts even before the $_GET ? So, this filter_input is not just a method that filters data, it’s more then that. Since, somehow, he acts even before the $_GET superglobal. :?


note: Of course this “somehow” hides a lot of ignorance of my part. :s

filter_input works on the values as-received by your script; values in the superglobal arrays may be altered in your script before you try to use filter_var on them.

// page requested with ?foo=bar

$_GET['foo'] = 'cat';

echo filter_input(INPUT_GET, FILTER_SANITIZE_STRING); // bar
echo filter_var($_GET['foo'], FILTER_SANITIZE_STRING); // cat

I might even go so far as suggesting to always use filter_input for those items which are available with it. The filter_var function can then be used at any other time, where filter_input just isn’t possible.