2019独角兽企业重金招聘Python工程师标准>>>
set_magic_quotes_runtime是用来设置PHP 环境配置的变量 magic_quotes_runtime 值。
0-关闭 1-打开
程序中检测状态用get_magic_quotes_runtime,返回 0 表示关闭本功能;返回 1 表示本功能打开。若magic_quotes_runtime 打开时,所有外部引入的数据库资料或者文件等等都会自动转为含有反斜线溢出字符的资料。
本 函数取得 PHP 环境配置的变量 magic_quotes_gpc (GPC, Get/Post/Cookie) 值。返回 0表示关闭本功能;返回 1 表示本功能打开。当 magic_quotes_gpc 打开时,所有的 ' (单引号), " (双引号), / (反斜线) and 空字符会自动加上转义符/;
其实这个函数就是判断有PHP有没有自动调用addslashes这个函数
<?php
echo get_magic_quotes_gpc(); //显示gpc状态值(0或1)
echo $_POST['lastname']; echo addslashes($_POST['lastname']);
Simao/'pig
if (!get_magic_quotes_gpc()) {
$lastname = addslashes($_POST['lastname']);
} else {
$lastname = $_POST['lastname'];
}
echo $lastname; // $sql = "INSERT INTO lastnames (lastname) VALUES ('$lastname')";
?>