简体   繁体   English

PHP&MySQL striplashes()问题

[英]PHP & MySQL striplashes() question

If magic_quotes_gpc is on will I still need to use striplashes() if no why? 如果magic_quotes_gpc处于打开状态,我仍然需要使用striplashes()如果没有,为什么? is so when and where? 是什么时候在哪里?

gpc in magic_quotes_gpc stands for GET, POST, COOKIE. magic_quotes_gpc gpc代表GET,POST,COOKIE。 So everything in $_GET , $_POST and $_COOKIE got escaped. 因此, $_GET$_POST$_COOKIE所有内容都转义了。 If magic_quotes_gpc is turned on, you should run stripslashes on variables in those arrays. 如果打开了magic_quotes_gpc,则应在这些数组中的变量上运行反斜杠。

Remember to run mysql_real_escape_string() on variables in queries (except for prepared statements) 记住要在查询中的变量上运行mysql_real_escape_string() (准备好的语句除外)

magic_quotes are deprecated, it's recommended to disable it and escape variables using mysql_real_escape_string() (for MySQL). magic_quotes已过时,建议使用mysql_real_escape_string()禁用它并转义变量(对于MySQL)。 Put the following in a .htaccess file for disabling magic_quotes_gpc: 将以下内容放在.htaccess文件中以禁用magic_quotes_gpc:

php_flag magic_quotes_gpc off
php_flag magic_quotes_runtime off

Not "still" but that's the only case when you will need this function. 不是“仍然”,而是在需要此功能时的唯一情况。

In the configuration file which being included in all your scripts. 在所有脚本中都包含的配置文件中。 Strip slashes from all GPC data. 从所有GPC数据中删除斜线。

The very good ptactice is make mysql_real_escape_string() ; 很好的做法是make mysql_real_escape_string() ; I am advise you to off magic_quotes. 我建议您关闭magic_quotes。 In PHP 6 magic quotes will be off. 在PHP 6中,魔术引号将被关闭。 If your hoster doesn't give you access to change this option, you can use the next function: 如果您的托管服务商不允许您更改此选项,则可以使用下一个功能:

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM