您的位置:首页 > 编程语言 > PHP开发

PHP关于mysql_real_escape_string的很奇怪的bug

2011-03-27 12:20 651 查看
长话短说,mysql_query串的安全问题是众所周知的,对拼入sql串的数据字符串要做mysql_real_escape_string(或mysql_escape_string),这些没有问题,可是,但是,在大名鼎鼎的php上面,有这样一个‘bug’,有时候你发现你escape后的串,输入到了数据库,调了好久,一步步跟踪数据的变化,后来发现在$_POST[]中变量就已经被escape了,于是你再调mysql_real_escape_string,就会多作一次变换,而结果就是:数据串'xxx"' => 'xxx/"' => 'xxx///"',结果可想而知,于是我查了一下php.ini,关键字(escape),发现这样一个选项:

 

; - magic_quotes_gpc = Off         [Performance]
;     Input data is no longer escaped with slashes so that it can be sent into
;     SQL databases without further manipulation.  Instead, you should use the
;     database vendor specific escape string function on each input element you
;     wish to send to a database.

 

很蛋疼。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息