when to use htmlspecialchars() function?

前端 未结 4 1993
自闭症患者
自闭症患者 2020-11-28 09:06

Hi I was wondering when is the appropriate place to use htmlspecialchars(). Is it before inserting data to database or when retrieving them from the database?

4条回答
  •  春和景丽
    2020-11-28 09:14

    You use htmlspecialchars EVERY time you output content within HTML, so it is interperted as content and not HTML.

    If you allow content to be treated as HTML, you have just opened the door to bugs at a minimum, and total XSS hacks at worst.

提交回复
热议问题