我的PHP版本是7.2.9-1。在以下练习中,assert
上有代码注入:
extract($_POST);
function goAway() {
error_log("Hacking attempt.");
header('Location: /error/');
}
if (!isset($pi) || !is_numeric($pi)) {
goAway();
}
if (!assert("(int)$pi == 3")) {
echo "This is not pi.";
} else {
echo "This might be pi.";
}
操作assert()评估PHP代码,它包含用户输入。但是,我使用pi=phpinfo()
,服务器不是phpinfo()
但只输出This might be pi.
。有人可以解释一下吗?
从PHP手册:
断言不应用于输入参数检查等常规运行时操作。根据经验,如果未激活断言检查,则代码应始终能够正常工作。
在PHP配置中可能只是禁用断言。检查你的php.ini
文件或assert_options()
。
此外,根据您提供的代码示例,这不是assert
的用途。