看程序是要注意上下文和程序运行的环境 在默认配置中 magic_quotes_gpc = on ;对传递数据转义 magic_quotes_runtime = off ;对数据库和文件数据不转义当配置为 magic_quotes_gpc = on ;对传递数据转义 magic_quotes_runtime = on ;对数据库和文件数据转义 时,入库前就要做stripslashes了。否则两次转义就出问题了因此,在程序中是否做addslashes和stripslashes要根据配置决定。 你可以通过这两个函数来决定操作 get_magic_quotes_gpc get_magic_quotes_runtime
也就是说如果以上配置中只要有一个为开,就得进行strip,否则就要add是否?
magic_quotes_gpc = off magic_quotes_runtime = off 入库是要addslashesmagic_quotes_gpc = on magic_quotes_runtime = off 入库是不要addslashes,假如没有做stripslashesmagic_quotes_gpc = off magic_quotes_runtime = on 入库是不要addslashesmagic_quotes_gpc = on magic_quotes_runtime = on 入库是要stripslashes
在默认配置中
magic_quotes_gpc = on ;对传递数据转义
magic_quotes_runtime = off ;对数据库和文件数据不转义当配置为
magic_quotes_gpc = on ;对传递数据转义
magic_quotes_runtime = on ;对数据库和文件数据转义
时,入库前就要做stripslashes了。否则两次转义就出问题了因此,在程序中是否做addslashes和stripslashes要根据配置决定。
你可以通过这两个函数来决定操作
get_magic_quotes_gpc
get_magic_quotes_runtime
magic_quotes_runtime = off
入库是要addslashesmagic_quotes_gpc = on
magic_quotes_runtime = off
入库是不要addslashes,假如没有做stripslashesmagic_quotes_gpc = off
magic_quotes_runtime = on
入库是不要addslashesmagic_quotes_gpc = on
magic_quotes_runtime = on
入库是要stripslashes
每次提交时判断下。
if( !get_magic_quotes_gpc() )
{
if( is_array($HTTP_GET_VARS) )
{
while( list($k, $v) = each($HTTP_GET_VARS) )
{
if( is_array($HTTP_GET_VARS[$k]) )
{
while( list($k2, $v2) = each($HTTP_GET_VARS[$k]) )
{
$HTTP_GET_VARS[$k][$k2] = addslashes($v2);
}
@reset($HTTP_GET_VARS[$k]);
}
else
{
$HTTP_GET_VARS[$k] = addslashes($v);
}
}
@reset($HTTP_GET_VARS);
} if( is_array($HTTP_POST_VARS) )
{
while( list($k, $v) = each($HTTP_POST_VARS) )
{
if( is_array($HTTP_POST_VARS[$k]) )
{
while( list($k2, $v2) = each($HTTP_POST_VARS[$k]) )
{
$HTTP_POST_VARS[$k][$k2] = addslashes($v2);
}
@reset($HTTP_POST_VARS[$k]);
}
else
{
$HTTP_POST_VARS[$k] = addslashes($v);
}
}
@reset($HTTP_POST_VARS);
} if( is_array($HTTP_COOKIE_VARS) )
{
while( list($k, $v) = each($HTTP_COOKIE_VARS) )
{
if( is_array($HTTP_COOKIE_VARS[$k]) )
{
while( list($k2, $v2) = each($HTTP_COOKIE_VARS[$k]) )
{
$HTTP_COOKIE_VARS[$k][$k2] = addslashes($v2);
}
@reset($HTTP_COOKIE_VARS[$k]);
}
else
{
$HTTP_COOKIE_VARS[$k] = addslashes($v);
}
}
@reset($HTTP_COOKIE_VARS);
}
}