php magic_quotes_runtime 和 magic_quotes_gpc的区别
原创
©著作权归作者所有:来自51CTO博客作者jackjie2010的原创作品,请联系作者获取转载授权,否则将追究法律责任
自 PHP 5.3.0 起,magic_quotes_runtime(),ereg() 函数已被废弃,不再使用。
报错例如:Deprecated: Function set_magic_quotes_runtime() is deprecated
表明已被废弃。
改函数的作用是对大多数函数返回数据,任何形式的外部来源包括数据库和文本文件里的数据将被转义,
引用手册上的原话:
If
magic_quotes_runtime is enabled, most functions
that return data from any sort of external source including databases and text
files will have quotes escaped with a backslash. If
magic_quotes_sybase is also
on, a single-quote is escaped with a single-quote instead of a backslash.
开启magic_quotes_gpc()函数,主要是对$_GET,$_POST,$_COOKIE数组里的函数自动转义,通常做法是判断改函数是否开启,如果没有则,用addslashes()函数进行转义。
if(!get_magic_quotes_gpc()){
$_GET = addslashes($_GET);
$_POST = addslashes($_POST);
$_COOKIE = addslashes($_COOKIE);
$_FILES = addslashes($_FILES);
}