PHP 中的魔术引号运行时是什么?

发布于 2024-08-18 19:30:16 字数 437 浏览 5 评论 0 原文

我完全意识到 PHP 中 Magic Quotes 的异常,它是如何邪恶的,我像害虫一样避免它们,但是 magic_quotes_runtime 是什么?来自 php.ini:

运行时生成的魔术引号 数据,例如来自 SQL、来自 exec() 的数据, 等等

我应该检查是否打开并关闭:

set_magic_quotes_runtime(false);

默认情况下它经常打开吗 我知道它在 5.3.0 中已被弃用,并在 6.0.0 中被删除,但由于我的脚本支持 5.1.0+,我想知道如何在“旧版”PHP 中处理此问题(如果相关)。

编辑:为了清楚起见,我想退出('关闭魔术引号');当魔法报价开启时。我不依赖他们!

I'm totally aware of the aberration of Magic Quotes in PHP, how it is evil and I avoid them like pest, but what are magic_quotes_runtime? From php.ini:

Magic quotes for runtime-generated
data, e.g. data from SQL, from exec(),
etc.

Is is something I should check if ON and turn OFF with:

set_magic_quotes_runtime(false);

Is it often ON by default? I know it's deprecated in 5.3.0 and removed in 6.0.0 but since my script support 5.1.0+ I would like to know how to handle this in "legacy" PHP (if it's relevant).

Edit: To make things clear I want to exit('Turn OFF Magic Quotes'); when Magic quotes are ON. I'm not relying on them!

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

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

发布评论

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

评论(3

叫思念不要吵 2024-08-25 19:30:16

如果启用 magic_quotes_runtime,大多数从任何类型的外部源(包括数据库和文本文件)返回数据的函数都将使用反斜杠转义引号。如果 magic_quotes_sybase 也打开,则使用单引号而不是反斜杠转义单引号。

http://www.php.net/manual /en/info.configuration.php#ini.magic-quotes-runtime

If magic_quotes_runtime is enabled, most functions that return data from any sort of external source including databases and text files will have quotes escaped with a backslash. If magic_quotes_sybase is also on, a single-quote is escaped with a single-quote instead of a backslash.

http://www.php.net/manual/en/info.configuration.php#ini.magic-quotes-runtime

白衬杉格子梦 2024-08-25 19:30:16

您可以使用 ini_get 来检查它的值,如下所示:

ini_get('magic_quotes_runtime');

另外,您应该在 function_exists 调用中包装对 set_magic_quotes_runtime/get_magic_quotes_runtime 的调用,如下所示:

if (function_exists('set_magic_quotes_runtime')) {
set_magic_quotes_runtime(true/false);
}

但是,当然,人们根本不应该依赖魔术引号,并且如果可能的话应该禁用它们。请参阅此链接以了解原因: Archive.org:http://www.php.net/manual/en/security.magicquotes.whynot.php

You could use ini_get to check for it's value, like this:

ini_get('magic_quotes_runtime');

Also you should wrap calls to set_magic_quotes_runtime/get_magic_quotes_runtime in function_exists calls, like that:

if (function_exists('set_magic_quotes_runtime')) {
set_magic_quotes_runtime(true/false);
}

But of course, one should not rely on magic quotes at all and should have them disabled if possible. Se this link for a coule of reasons why: Archive.org: http://www.php.net/manual/en/security.magicquotes.whynot.php

心在旅行 2024-08-25 19:30:16

如果魔术引号打开,php 将自动转义 POST 或 GET 变量中的引号,并在从数据库中提取数据时自动取消转义它们。

如果你使用诸如addslashes()、mysql_escape_string()或mysql_real_escape_string()之类的东西并加上魔术引号,你最终会得到双转义引号。

它邪恶的原因与addslashes() 和mysql_escape_string() 邪恶的原因相同——因为它没有捕获在字符串中放入引号的所有可能方法。它给你一种错误的安全感,让你认为你不必再担心转义引号,而实际上你仍然这样做。

另外,好像转义字符串还不足以满足 PITA 的要求,现在您必须在尝试转义或取消转义字符串之前检查魔术引号是否打开或关闭,以避免双重转义。

If magic quotes are ON, php will automatically escape quotes coming in POST or GET variables and automatically un-escape them when pulling data out of a database for example.

If you use things like addslashes(), mysql_escape_string() or mysql_real_escape_string() with magic quotes on, you'll end up double-escaping quotes.

The reason it's evil is the same reason addslashes() and mysql_escape_string() are evil - because it doesn't capture every possible method of putting a quote in a string. It gives you a false sense of security in thinking that you don't have to worry about escaping quotes anymore when in reality you still do.

Also, as if escaping strings wasn't enough of a PITA already, now you have to check if magic quotes are on or off before you try to escape or un-escape a string to avoid double escaping.

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