PHP关于mysql_real_escape_string的很奇怪的bug

来源:互联网 发布:web中js兼容性问题 编辑:程序博客网 时间:2024/06/05 02:16

长话短说,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.

 

很蛋疼。

原创粉丝点击