gpt4 book ai didi

php - PHP 中的 register_globals 是什么?

转载 作者:IT老高 更新时间:2023-10-28 12:03:05 25 4
gpt4 key购买 nike

谁能举例说明 register_globals 是什么?
global $user_id; 是否被视为全局寄存器?

最佳答案

register_globals 指令:

register_globals 是一个内部 PHP 设置,它将 $_REQUEST 数组的元素注册为变量。如果您通过 POSTGET 在表单中提交值,则该输入的值将自动通过 PHP 脚本中的变量访问,该变量以输入字段。

换句话说,如果您提交的表单包含 username 文本字段,则表达式 ($username === $_POST['username']) 在脚本的最开始会返回 true

它的恶名归因于它打开了许多安全漏洞,特别是对于从安全角度来看不遵循严格编码风格的人。

经典例子:

if(user_is_admin($user))
{
$authorized = true;
}

if($authorized)
{
// let them do anything they want
}

现在,如果您在 Web 浏览器中访问该脚本并且服务器启用了 register_globals,您只需将 ?authorized=1 附加到 URL 和 God-mode将被启用!

全局关键字:

global 是关键字,与 register_globals 关系不大。

以下是它的使用示例:

$foo = 'bar';

baz();

function baz()
{
echo $foo; // PHP warns you about trying to use an uninitialized variable
// and nothing is output (because $foo doesn't exist here)
}

buzz();

function buzz()
{
global $foo; // Enables the use of $foo in this scope

echo $foo; // Prints 'bar' to screen
}

关于php - PHP 中的 register_globals 是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3593210/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com