如果 php.ini/.htaccess 不可编辑,如何删除魔术引号?
由于某种原因,我所有的引号都被转义并显示为 \"。以前,没问题。然后我查看 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试一下这段代码,它过去对我有用。
Give this code a try, it's worked for me in the past.
您使用哪个 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 usefilter_input()
orfilter_input_array()
. It seems that it ignores the setting of themagic_quotes_gpc
-directive and uses the raw data (the default filter isFILTER_UNSAFE_RAW
)