Should I use both striptags() and htmlspecialchars() to prevent XSS?

后端 未结 1 942
傲寒
傲寒 2020-12-10 05:19

Does this depend on if the input is going to be printed to the user? In my case I need to return the input back to the user (comments and bio).

Thanks!!!

相关标签:
1条回答
  • 2020-12-10 06:18

    htmlspecialchars() is enough to prevent XSS.

    Strip tags removes tags but not special characters like " or ', so if you use strip_tags() you also have to use htmlspecialchars().

    If you want users' comments to be displayed like they typed them, don't use strip_tags, use htmlspecialchars() only.

    0 讨论(0)
提交回复
热议问题