Htmlentities vs addslashes vs mysqli_real_escape_string

前端 未结 7 1100
悲哀的现实
悲哀的现实 2020-12-18 03:04

I\'ve been doing some reading on securing PHP applications, and it seems to me that mysqli_real_escape_string is the correct function to use when inserting data

7条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-18 03:33

    Note: Using htmlentities() in an UTF-8 encoded document should be avoided. See:

    • Interfacing with Systems using other Charsets
    • Common Problem Areas with UTF-8

    Pay attention to (quoted from phpwact.org):

    With modern web browsers and widespead support for UTF-8, you don’t need htmlentities because all of these characters can be represented directly in UTF-8. More importantly, in general, only browsers support HTML‘s special characters - a normal text editor, for example, is unaware of HTML entities. Depending on what you’re doing, using htmlentities may reduce the ability of other systems to “consume” your content.

    Also (not confirmed but sounds reasonable - from anon comment here), character entities (stuff like » or —) do not work when a document is served as application/xml+xhtml (unless you define them). You can still get away with the numeric form though.

提交回复
热议问题