magic_quotes_gpc = 1 影响哪些超全局变量?

发布于 2024-08-17 20:22:43 字数 893 浏览 8 评论 0原文

通过查看该指令的名称,人们可能会认为 magic_quotes 仅适用于 $_GET$_POST$_COOKIE< /code> 超全局变量,但有一个一个令人不安的评论PHP手册上:

请注意,当 magic_quotes_gpc不仅设置 $_POST$_GET$_REQUEST$_COOKIE 数组值被削减。实际上 $GLOBALS 数组中的每个字符串值 被削减,即。 $GLOBALS['_SERVER']['PATH_INFO'](或 $_SERVER['PATH_INFO'])。

谁能证实这是真的吗?超全局变量是 $GLOBALS$_SERVER$_FILES$_SESSION$_ENV 也受到影响吗?

还有一个问题,如果我在 $_GET$_POST$_COOKIE 数组上迭代 stripslashes() ,我还需要迭代 $_REQUEST 数组?或者更改会自动反映吗?

By looking at the name of this directive one may think that magic_quotes are only applied to $_GET, $_POST and $_COOKIE superglobals but there is one perturbing comment on the PHP Manual:

Please note, that when
magic_quotes_gpc is set not only
$_POST, $_GET, $_REQUEST, $_COOKIE
arrays values are slashed. Actually
every string value in $GLOBALS array
is slashed, ie.
$GLOBALS['_SERVER']['PATH_INFO'] (or
$_SERVER['PATH_INFO']).

Can anyone confirm that this is true? Are the superglobals $GLOBALS, $_SERVER, $_FILES, $_SESSION and $_ENV affected as well?

One more question, if I iterate stripslashes() over the $_GET, $_POST and $_COOKIE arrays do I also need to iterate through the $_REQUEST array? Or are the changes automatically reflected?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

方觉久 2024-08-24 20:22:43

不管怎样,我建议你不要依赖GPC,因为它在较新的PHP版本中已被弃用...

它可能与你的问题不太相关,但在提出的SQL安全替代方案问题上,我通常使用准备好的语句+ mysql_real_escape_string MySQL。

为了使其接近完美,它涉及几个函数,因为它还应该支持整数、布尔值和空值,但您可以查看 NaturePhp .

Either way i'd advise you not to rely on GPC as it has been deprecated on newer PHP versions...

It may not be too relevant for your question but on the raised issue of SQL security alternatives i usually use prepared statements + mysql_real_escape_string for MySQL.

To make it close to perfect it involves a couple of functions as it also should support integer, boolean and null values but you can take a look at the source code on the Database and Database_mysql classes on NaturePhp .

断桥再见 2024-08-24 20:22:43

我已使用 magic_quotes_gpc = On$_SERVERLightTPD 1.4.20PHP 5.3.0 上运行了一些测试> 没有改变(至少 [SERVER_NAME] => local'host 没有改变)。 $_SESSION 也不受 magic_quotes 的影响。

$_GET$_POST$_COOKIE$_REQUEST 受到影响(及其 $GLOBALS< /code> 对应)。

此外,GPC 超全局变量中的更改不会自动反映在 $_REQUEST 中。

至于 $_FILES$_ENV 超全局变量,我无法在 ATM 上测试它们。


我终于运行了这个测试,令我惊讶的是,$_FILESphp://input 都受到影响。

I've run some tests on LightTPD 1.4.20 and PHP 5.3.0 with magic_quotes_gpc = On and $_SERVER wasn't altered (at least [SERVER_NAME] => local'host didn't). $_SESSION also isn't affected by magic_quotes.

$_GET, $_POST, $_COOKIE and $_REQUEST were affected (and their $GLOBALS counterparts).

Also, the changes in the GPC superglobals aren't automatically reflected in $_REQUEST.

As for the $_FILES and $_ENV superglobals I'm not able to test them ATM.


I've finally ran this test and, to my surprise, both $_FILES and php://input are affected.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文