[英]PHP & MySQL striplashes() question
如果magic_quotes_gpc
处于打开状态,我仍然需要使用striplashes()
如果没有,为什么? 是什么时候在哪里?
magic_quotes_gpc
gpc代表GET,POST,COOKIE。 因此, $_GET
, $_POST
和$_COOKIE
所有内容都转义了。 如果打开了magic_quotes_gpc,则应在这些数组中的变量上运行反斜杠。
记住要在查询中的变量上运行mysql_real_escape_string()
(准备好的语句除外)
magic_quotes已过时,建议使用mysql_real_escape_string()
禁用它并转义变量(对于MySQL)。 将以下内容放在.htaccess文件中以禁用magic_quotes_gpc:
php_flag magic_quotes_gpc off
php_flag magic_quotes_runtime off
不是“仍然”,而是在需要此功能时的唯一情况。
在所有脚本中都包含的配置文件中。 从所有GPC数据中删除斜线。
很好的做法是make mysql_real_escape_string()
; 我建议您关闭magic_quotes。 在PHP 6中,魔术引号将被关闭。 如果您的托管服务商不允许您更改此选项,则可以使用下一个功能:
function stripslashes_deep($value) {
$value = is_array($value) ?
array_map('stripslashes_deep', $value) :
stripslashes($value);
return $value;
}
if((function_exists("get_magic_quotes_gpc") && get_magic_quotes_gpc()) || (ini_get('magic_quotes_sybase') && (strtolower(ini_get('magic_quotes_sybase'))!="off")) ){
stripslashes_deep($_GET);
stripslashes_deep($_POST);
stripslashes_deep($_COOKIE);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.