如何在共享主机上关闭魔术引号? [英] How to turn off magic quotes on shared hosting?

查看:79
本文介绍了如何在共享主机上关闭魔术引号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想关闭PHP的魔术引号.我无权访问php.ini.

I want to turn off PHP's magic quotes. I don't have access to php.ini.

当我尝试将php_flag magic_quotes_gpc off添加到我的.htaccess文件时,出现500个内部服务器错误.这是我的.htaccess文件的样子:

When I tried to add php_flag magic_quotes_gpc off to my .htaccess file, I get a 500 internal server error. This is what my .htaccess file looks like:

AddType x-mapp-php5 .php
php_flag magic_quotes_gpc off

然后我尝试使用ini_set('magic_quotes_gpc', 'O'),但是没有效果.

Then I tried to use ini_set('magic_quotes_gpc', 'O'), but that had no effect.

如何关闭魔术引号?

推荐答案

根据手册,您通常可以在共享主机上安装自定义php.ini,其中不使用mod_php,因此php_value指令会导致错误.对于suexec/FastCGI设置,在任何情况下都有每个Web空间php.ini是很常见的.

As per the manual you can often install a custom php.ini on shared hosting, where mod_php isn't used and the php_value directive thus leads to an error. For suexec/FastCGI setups it is quite common to have a per-webspace php.ini in any case.

-

我认为O(大写字母o)不是设置ini标志的有效值.您需要使用true/false,1/0或"on"/"off"值.

I don't think O (uppercase letter o) is a valid value to set an ini flag. You need to use a true/false, 1/0, or "on"/"off" value.

ini_set( 'magic_quotes_gpc', 0 );   // doesn't work

编辑

在检查 ini设置列表后,我看到magic_quotes_gpc是设置(在4.2.3之后),这意味着您无法使用ini_set()进行更改(只能使用ini_set()更改PHP_INI_ALL设置)

After checking the list of ini settings, I see that magic_quotes_gpc is a PHP_INI_PERDIR setting (after 4.2.3), which means you can't change it with ini_set() (only PHP_INI_ALL settings can be changed with ini_set())

这意味着您必须使用.htaccess文件来执行此操作-或-实现脚本以反转魔术引号的效果.像这样

What this means is you have to use an .htaccess file to do this - OR - implement a script to reverse the effects of magic quotes. Something like this

if ( in_array( strtolower( ini_get( 'magic_quotes_gpc' ) ), array( '1', 'on' ) ) )
{
    $_POST = array_map( 'stripslashes', $_POST );
    $_GET = array_map( 'stripslashes', $_GET );
    $_COOKIE = array_map( 'stripslashes', $_COOKIE );
}

这篇关于如何在共享主机上关闭魔术引号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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