如何在运行时禁用PHP魔术引号? [英] How can I disable PHP magic quotes at runtime?

查看:117
本文介绍了如何在运行时禁用PHP魔术引号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一组PHP脚本,这些脚本将在某些不同的设置中运行,其中一些脚本共享带有恐怖引用的主机托管(恐怖).没有控制PHP或Apache配置的能力,我可以在脚本中执行任何操作以在运行时禁用PHP引号吗?

I'm writing a set of PHP scripts that'll be run in some different setups, some of them shared hosting with magic quotes on (the horror). Without the ability to control PHP or Apache configuration, can I do anything in my scripts to disable PHP quotes at runtime?

最好不要在代码中假设使用魔术引号,以便我可以在可能具有或没有魔术引号的不同主机上使用相同的脚本.

It'd be better if the code didn't assume magic quotes are on, so that I can use the same scripts on different hosts that might or might not have magic quotes.

推荐答案

magic_quoted_runtime 可以在运行时禁用.但是 magic_quotes_gpc 不能在运行时被禁用( PHP_INI_ALL 直到PHP 4.2才可以更改. 3,从那时起 PHP_INI_PERDIR );您只能删除它们:

Only magic_quoted_runtime can be disabled at runtime. But magic_quotes_gpc can’t be disabled at runtime (PHP_INI_ALL changable until PHP 4.2.3, since then PHP_INI_PERDIR); you can only remove them:

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 further information see Disabling Magic Quotes.

这篇关于如何在运行时禁用PHP魔术引号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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