为什么使用 filter_input() 更好?

2021-12-23 00:00:00 filter security php

这应该是一个基本问题,但为什么使用这样的东西更好:

This should be a elementary question but why is better to use something like this:

$pwd = filter_input(INPUT_POST, 'pwd');

而不仅仅是:

$pwd = $_POST['pwd'];

PS:我知道过滤器扩展可以与更多参数一起使用,以提供额外的清理级别.

PS: I understand that the filter extension can be used with more arguments to provide an additional level of sanitization.

推荐答案

不是.$_GET$_POST$_COOKIE$_REQUEST 是 使用默认过滤器过滤.filter_input(INPUT_POST, 'pwd') 没有附加参数也使用默认过滤器.所以完全没有区别.

It's not. $_GET, $_POST, $_COOKIE and $_REQUEST are filtered with default filter. filter_input(INPUT_POST, 'pwd') without additional parameters also uses the default filter. So there is no difference at all.

相关文章