我正在为一些简单的功能开发一个基本的 API。我正在捕获如下输入:
if ($action == 'delete' && isset($_POST['targetId']) && isset($_POST['userId'])) {
//The isset causes "Do not access Superglobal _POST array directly" warning in Netbeans
$userId = filter_input(INPUT_POST, 'userId');
$beamId = filter_input(INPUT_POST, 'targetId');
}
我是否应该使用filter_input来检查值是否已设置?喜欢:
if ($action == 'delete' && filter_input(INPUT_POST, 'targetId') && filter_input(INPUT_POST, 'userId')) {
}
我不是在这里考虑选项,而是我会对安全且防黑客的最正确的解决方案感到满意。
编辑:是的,以上信息将用作 SQL 的输入
最佳答案
另一个解决方案可以使用filter_has_var()。
if (filter_has_var(INPUT_POST, "userId")) {
//occurs when $_POST['userId'] is set, even when empty
}
关于php - 在 PHP 中正确使用 isset 和 filter_input,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23731976/