如果 php.ini/.htaccess 不可编辑,如何删除魔术引号?

发布于 2024-12-06 07:44:53 字数 804 浏览 0 评论 0原文

由于某种原因,我所有的引号都被转义并显示为 \"。以前,没问题。然后我查看 phpinfo() ,发现我的 magic_quotes_gpc 已打开。但是,我找不到目录 /usr/local/ lib/ 其中 php.ini 文件所在,我无法编辑我的 .htaccess 文件(收到 500 内部服务器错误)。

我尝试将其放在我的脚本文件(包含在所有页面中)的顶部:

if (get_magic_quotes_gpc()) {
    $process = array(&$_GET, &$_POST, &$_COOKIE, &$_REQUEST);
    while (list($key, $val) = each($process)) {
        foreach ($val as $k => $v) {
            unset($process[$key][$k]);
            if (is_array($v)) {
                $process[$key][stripslashes($k)] = $v;
                $process[] = &$process[$key][stripslashes($k)];
            } else {
                $process[$key][stripslashes($k)] = stripslashes($v);
            }
        }
    }
    unset($process);
}

但是,“并且 ' 在我的页面上仍然有反斜杠。

我做错了什么?

For some reason, all my quotes are being escaped and displayed as \". Previously, it was okay. Then I looked at phpinfo() and saw that my magic_quotes_gpc is turned on. However, I cannot find the directory /usr/local/lib/ where php.ini file is and I cannot edit my .htaccess file (gets 500 Internal Server Error).

I tried putting this instead on top of my scripts file (which is included in all pages):

if (get_magic_quotes_gpc()) {
    $process = array(&$_GET, &$_POST, &$_COOKIE, &$_REQUEST);
    while (list($key, $val) = each($process)) {
        foreach ($val as $k => $v) {
            unset($process[$key][$k]);
            if (is_array($v)) {
                $process[$key][stripslashes($k)] = $v;
                $process[] = &$process[$key][stripslashes($k)];
            } else {
                $process[$key][stripslashes($k)] = stripslashes($v);
            }
        }
    }
    unset($process);
}

But still, the " and ' on my pages still have the backslashes in them.

What am I doing wrong?

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

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

发布评论

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

评论(2

把昨日还给我 2024-12-13 07:44:53

尝试一下这段代码,它过去对我有用。

<?php
if (function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()) {
        $quotes_sybase = strtolower(ini_get('magic_quotes_sybase'));
        $unescape_function = (empty($quotes_sybase) || $quotes_sybase === 'off') ? 'stripslashes($value)' : 'str_replace("\'\'","\'",$value)';
    $stripslashes_deep = create_function('&$value, $fn', '
        if (is_string($value)) {
            $value = ' . $unescape_function . ';
        } else if (is_array($value)) {
            foreach ($value as &$v) $fn($v, $fn);
        }
    ');

    // Unescape data
    $stripslashes_deep($_POST, $stripslashes_deep);
    $stripslashes_deep($_GET, $stripslashes_deep);
    $stripslashes_deep($_COOKIE, $stripslashes_deep);
    $stripslashes_deep($_REQUEST, $stripslashes_deep);
}

Give this code a try, it's worked for me in the past.

<?php
if (function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()) {
        $quotes_sybase = strtolower(ini_get('magic_quotes_sybase'));
        $unescape_function = (empty($quotes_sybase) || $quotes_sybase === 'off') ? 'stripslashes($value)' : 'str_replace("\'\'","\'",$value)';
    $stripslashes_deep = create_function('&$value, $fn', '
        if (is_string($value)) {
            $value = ' . $unescape_function . ';
        } else if (is_array($value)) {
            foreach ($value as &$v) $fn($v, $fn);
        }
    ');

    // Unescape data
    $stripslashes_deep($_POST, $stripslashes_deep);
    $stripslashes_deep($_GET, $stripslashes_deep);
    $stripslashes_deep($_COOKIE, $stripslashes_deep);
    $stripslashes_deep($_REQUEST, $stripslashes_deep);
}
走走停停 2024-12-13 07:44:53

您使用哪个 PHP 版本?

如果您使用的版本大于 5.2,则可以使用 filter_input()filter_input_array()。它似乎忽略了magic_quotes_gpc指令的设置并使用原始数据(默认过滤器是FILTER_UNSAFE_RAW)

Which PHP-version do you use?

If you use a version larger than 5.2, than you can use filter_input() or filter_input_array(). It seems that it ignores the setting of the magic_quotes_gpc-directive and uses the raw data (the default filter is FILTER_UNSAFE_RAW)

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