mysql_real_escape_string足以防SQL注入吗?
PHP手册中有这样一段注释:
注意:如果不使用该功能 转义数据,查询容易受到攻击 SQL注入攻击。
这足以防sql注入吗?如果没有的话,能否给出一个例子以及一个好的防sql注入的解决方案?
In PHP Manual, there is a note:
Note: If this function is not used to
escape data, the query is vulnerable
to SQL Injection Attacks.
Is this enough to anti sql injection? If not, could you give an example and a good solution to anti sql injection?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
mysql_real_escape_string
通常足以避免 SQL 注入。但这确实取决于它是否没有错误,即存在一些未知的小机会它容易受到攻击(但这尚未在现实世界中显现出来)。在概念层面上完全排除 SQL 注入的更好替代方案是准备好的语句。这两种方法完全取决于您是否正确应用它们;也就是说,如果你把事情搞砸了,两者都不会保护你。mysql_real_escape_string
is usually enough to avoid SQL injection. This does depend on it being bug free though, i.e. there's some small unknown chance it is vulnerable (but this hasn't manifested in the real world yet). A better alternative which completely rules out SQL injections on a conceptual level is prepared statements. Both methods entirely depend on your applying them correctly; i.e. neither will protect you if you simply mess it up anyway.据我所知,这是避免 SQL 注入攻击的可靠方法。
As far as i know this is a solid way to avoid SQL Injection attacks.
最好的解决方案是 PDO。
如果您使用传统的
mysql_query
然后通过 mysql_real_escape_string() 运行所有数据就足够了。The best solution is PDO.
If you're using the traditional
mysql_query
then running all of your data throughmysql_real_escape_string()
is enough.