既然 $_POST 会自动在引号前添加斜杠,为什么还要麻烦使用 mysql_real_escape_string() 呢?

发布于 2024-08-11 08:26:11 字数 138 浏览 2 评论 0原文

在 PHP 中,$_POST 自动在引号前添加斜杠,那么为什么还要应用 mysql_real_escape_string() 呢?例如,当我在输入字段中输入 'rrr 时,当我回显它时,我会得到 \'rrr

In PHP, $_POST add slashes before a quotation mark automatically, so why bother applying mysql_real_escape_string()? For example, when I input 'rrr in an input field, and I get \'rrr when I echo it.

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

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

发布评论

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

评论(3

夜还是长夜 2024-08-18 08:26:11

因为只有在 php 配置中启用 MacigQuotes 时才会发生这种情况,据我所知,这种情况现在相当不常见。此外,mysql_real_escape_string 还转义其他 MySQL 相关字符。

查看 http://php.net/manual/en/security.magicquotes.php< /a> 有关魔术引号的更多信息。

正如您所看到的,该指令已经有一个弃用警告,因此您应该检查您的服务器配置^^

编辑:要禁用魔术引号,请在您的 xampp 文件夹中搜索 php.ini,然后添加或更改(如果存在) ,以下指令:

; Magic quotes
;

; Magic quotes for incoming GET/POST/Cookie data.
magic_quotes_gpc = Off

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

; Use Sybase-style magic quotes (escape ' with '' instead of \').
magic_quotes_sybase = Off

Because that only happens if MacigQuotes is enabled in your php configuration, which, as far as I know, is fairly uncommon nowadays. Also, mysql_real_escape_string also escapes other MySQL related characters.

Check out http://php.net/manual/en/security.magicquotes.php for more information on magic quotes.

As you can see, there already is a deprecation warning for this directive, so you should check your server configuration anyway^^

Edit: To disable magic quotes, search in your xampp folder for the php.ini, and add, or change if present, the following directives:

; Magic quotes
;

; Magic quotes for incoming GET/POST/Cookie data.
magic_quotes_gpc = Off

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

; Use Sybase-style magic quotes (escape ' with '' instead of \').
magic_quotes_sybase = Off
谈情不如逗狗 2024-08-18 08:26:11
  1. mysql_real_escape_string 转义的不仅仅是单引号,因为还有其他可能导致注入问题的字符。
  2. 如果启用了 magic_quotes,PHP 只会在 POSTed 输入中添加斜杠,这被认为是不好的做法(因为它会导致懒惰并且不使用 real_escape_string 之类的东西!)
  1. mysql_real_escape_string escapes more than just single-quotes, because there are other chars that can cause injection issues.
  2. PHP only adds slashes to POSTed input if magic_quotes is enabled, which is considered bad practice (because it leads to laziness and not using things like real_escape_string!)
深者入戏 2024-08-18 08:26:11

魔术引号 自 PHP 5.3.0 起已弃用,并已过时PHP 6.0 的。

编辑:所以不能依赖自动斜杠,因为它们已被大多数 PHP 安装弃用,并且很快将根本不起作用。

Magic quotes was deprecated as of PHP 5.3.0 and is obsolete as of PHP 6.0.

Edit: So the auto slashes can't be relied on because they are deprecated by most PHP installations, and soon will not work at all.

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