使用 magic_quotes() 是否影响 mysql_real_escape_string() 的使用

发布于 2024-08-29 23:59:37 字数 237 浏览 2 评论 0 原文

如果我打开magic_quotes并且使用mysql_real_escape_string,字符串会被双重转义吗?会引起问题吗?

我基于 get_magic_quotes() 函数假设是这样,但只是寻求确认。

(PS,提出这个问题比在我的办公室中测试它更容易,因为我们拥有所有的安全措施 - 我需要 10-15 时间来配置所有内容以获得可用的环境)

If I have magic_quotes switched on and I use mysql_real_escape_string, will the string be double escaped? Will it cause problems?

I assume so based on the get_magic_quotes() function but just seeking confirmation.

(P.S. It's easier to ask this question than test it in my office with all the security we have in place - It takes me 10-15 to configure everything to get a usable environment)

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

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

发布评论

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

评论(4

━╋う一瞬間旳綻放 2024-09-05 23:59:37

阅读 mysql_real_escape_string 的文档 (我希望这也不难):

注意:如果启用magic_quotes_gpc,请首先应用stripslashes() 到数据。对已经转义的数据使用此函数将转义数据两次。

Read the documentation of mysql_real_escape_string (I hope this is not difficult as well):

Note: If magic_quotes_gpc is enabled, first apply stripslashes() to the data. Using this function on data which has already been escaped will escape the data twice.

蛮可爱 2024-09-05 23:59:37

如果您转义从 get/post/cookie 输入获得的值,它将已经具有 addslashes() 应用于它,因此通过 mysql_real_escape_string() 传递它实际上将是双引号。

要剥离它们:

if (get_magic_quotes_gpc())
{
    $_GET = json_decode(stripslashes(json_encode($_GET, JSON_HEX_APOS)), true);
    $_POST = json_decode(stripslashes(json_encode($_POST, JSON_HEX_APOS)), true);
    $_COOKIE = json_decode(stripslashes(json_encode($_COOKIE, JSON_HEX_APOS)), true);
    $_REQUEST = json_decode(stripslashes(json_encode($_REQUEST, JSON_HEX_APOS)), true);
    ini_set('magic_quotes_gpc', 0);
}

这个问题还有一些其他选项用于剥离引号/处理可怕的 magic_quotes_gpc PHP“功能”。

If you escape a value obtained from get/post/cookie input, it will already have addslashes() applied to it, so passing it through mysql_real_escape_string() will in fact, double quote.

To strip em:

if (get_magic_quotes_gpc())
{
    $_GET = json_decode(stripslashes(json_encode($_GET, JSON_HEX_APOS)), true);
    $_POST = json_decode(stripslashes(json_encode($_POST, JSON_HEX_APOS)), true);
    $_COOKIE = json_decode(stripslashes(json_encode($_COOKIE, JSON_HEX_APOS)), true);
    $_REQUEST = json_decode(stripslashes(json_encode($_REQUEST, JSON_HEX_APOS)), true);
    ini_set('magic_quotes_gpc', 0);
}

This question has some other options for stripping quotes / dealing with the horrible magic_quotes_gpc PHP 'feature'.

青萝楚歌 2024-09-05 23:59:37

当然,最简单的方法就是关闭 magic_quotes。
与通常的 PHP/Apache 配置一样,

php_flag magic_quotes_gpc 0

.htaccess 文件中的这一行将完成此操作。

但出于兼容性目的,也可以在某些配置文件中使用函数。

if ( get_magic_quotes_gpc( ) ) {
  $_GET = array_map_recursive('stripslashes', $_GET) ;
  $_POST = array_map_recursive('stripslashes', $_POST) ;
  $_COOKIE = array_map_recursive('stripslashes', $_COOKIE) ;
  $_REQUEST = array_map_recursive('stripslashes', $_REQUEST) ;
  if (isset($_SERVER['PHP_AUTH_USER'])) stripslashes($_SERVER['PHP_AUTH_USER']); 
  if (isset($_SERVER['PHP_AUTH_PW'])) stripslashes($_SERVER['PHP_AUTH_PW']);
}

最简单的之一

Of course, the easiest way is to turn magic_quotes off.
wuth usual PHP/Apache config, this line

php_flag magic_quotes_gpc 0

in the .htaccess file will do the thing.

but for the compatibility purpose, a function can be used in some config file too.

if ( get_magic_quotes_gpc( ) ) {
  $_GET = array_map_recursive('stripslashes', $_GET) ;
  $_POST = array_map_recursive('stripslashes', $_POST) ;
  $_COOKIE = array_map_recursive('stripslashes', $_COOKIE) ;
  $_REQUEST = array_map_recursive('stripslashes', $_REQUEST) ;
  if (isset($_SERVER['PHP_AUTH_USER'])) stripslashes($_SERVER['PHP_AUTH_USER']); 
  if (isset($_SERVER['PHP_AUTH_PW'])) stripslashes($_SERVER['PHP_AUTH_PW']);
}

one of the easiest

贱人配狗天长地久 2024-09-05 23:59:37

如果我打开了 magic_quotes 并且
我使用mysql_real_escape_string,会
字符串需要双重转义吗?

是的,它会,但你可以这样做:

if (get_magic_quotes_gpc())
{
  $escaped = stripslashes($your_vars);
}

注意:你可以禁用 PHP.ini 中的魔术引号或使用以下函数覆盖它:

// no more magic quotes
function get_magic_quotes_gpc()
{ 
  return false;
}

If I have magic_quotes switched on and
I use mysql_real_escape_string, will
the tring be double escaped?

Yes, it will but you could do something like this though:

if (get_magic_quotes_gpc())
{
  $escaped = stripslashes($your_vars);
}

Note: You can disable the magic quotes from PHP.ini or use the below function to override it:

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