附有“魔幻语录"已禁用,为什么 PHP/WordPress 会继续自动转义我的 POST 数据? [英] With "magic quotes" disabled, why does PHP/WordPress continue to auto-escape my POST data?

查看:23
本文介绍了附有“魔幻语录"已禁用,为什么 PHP/WordPress 会继续自动转义我的 POST 数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个简单的问题,但答案却出奇地难以捉摸.

It's a simple question with a strangely elusive answer.

get_magic_quotes_gpc() 报告 0.我再说一遍,魔术引号已关闭.魔术引号似乎已在 php.ini 中禁用(不是在运行时).

get_magic_quotes_gpc() reports 0. I repeat, magic quotes are off. Magic quotes appear to have been disabled in php.ini (not at runtime).

尽管如此,在 PHP 中访问时,包括单引号 (') 在内的所有 POST 数据都会被转义.这可能是什么原因造成的?

Nevertheless, all POST data including single quotes (') is escaped when accessed in PHP. What could be causing this?

在准备测试用例时,我发现了问题的大致来源.我们正在引导 WordPress,因为我们的应用程序与 WordPress 多站点安装集成.当我禁用 WordPress 引导时,自动转义被禁用.WordPress 的自动转义码在哪里?

While preparing a test case, I discovered the general origin of the problem. We're bootstrapping WordPress as our application integrates with a WordPress multisite installation. When I disable the WordPress bootstrapping, the auto-escaping is disabled. Where may WordPress' auto-escape code be located?

推荐答案

我想我找到了.问题(错误):http://core.trac.wordpress.org/ticket/18322

I think I found it. Problem (bug): http://core.trac.wordpress.org/ticket/18322

解决方案:http://codex.wordpress.org/Function_Reference/stripslashes_deep

    $_GET       = array_map('stripslashes_deep', $_GET);
    $_POST      = array_map('stripslashes_deep', $_POST);
    $_COOKIE    = array_map('stripslashes_deep', $_COOKIE);
    $_SERVER    = array_map('stripslashes_deep', $_SERVER);
    $_REQUEST   = array_map('stripslashes_deep', $_REQUEST);

<小时>

注意:正如@Alexandar O'Mara 所建议的,您可能需要重新考虑像这样覆盖超全局变量.例如,如果它适合您的情况,您可以使用诸如 $post = array_map('stripslashes_deep', $_POST);

另见@quickshiftin 的优秀回答.

Also see @quickshiftin's excellent answer.

这篇关于附有“魔幻语录"已禁用,为什么 PHP/WordPress 会继续自动转义我的 POST 数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆