如果我输入文本,例如,不要在输入字段中输入,然后尝试使用PHP准备语句将其显示或保存到MySQL中,那么在单引号之前我会得到一个额外的反斜杠。
$name = $_POST['name'];
echo "name=($name)";这个输出: don\'t和我还会得到存储在MySQL中的额外反斜杠。
我怎样才能避免这种情况,并且仍然能够输入反斜杠?
你好,Magnus Strand
发布于 2012-09-21 13:07:20
条纹斜杠的用法,
echo stripslashes("Who\'s Kai Jim?"); //Who's Kai Jim?发布于 2012-09-21 13:09:23
打开您的php.ini文件,转到第460行(几乎),并关闭魔术引号。喜欢
; Magic quotes for incoming GET/POST/Cookie data.
magic_quotes_gpc = Off
; Magic quotes for runtime-generated data, e.g. data from SQL, from exec(), etc.
magic_quotes_runtime = Off保持魔术引号是一个很好的技术,从您的应用程序安全性开始。魔术名言天生就被打破了。它们的目的是对PHP脚本的输入进行清理,但是如果不知道如何使用该输入,就不可能正确地进行清理。
魔法引号上的PHP手册页同意:
"This feature has been DEPRECATED as of PHP 5.3.0 and REMOVED as of PHP 6.0.0. Relying on this feature is highly discouraged. Magic Quotes is a process that automagically escapes incoming data to the PHP script. It's preferred to code with magic quotes off and to instead escape the data at runtime, as needed."https://stackoverflow.com/questions/12530799
复制相似问题