PHP & mySQL: When exactly to use htmlentities?

后端 未结 4 1169
遥遥无期
遥遥无期 2020-12-04 20:14

PLATFORM: PHP & mySQL

For my experimentation purposes, I have tried out few of the XSS injections myself on my own website. Consider this situat

4条回答
  •  醉梦人生
    2020-12-04 21:02

    1. Only before you are printing value(no matter from DB or from $_GET/$_POST) into HTML. htmlentities have nothing to do with database.
    2. B is overkill. You should mysql_real_escape_string before inserting to DB, and htmlentities before printing to HTML. You don't need to strip tags, after htmlentities tags will be displayed on screen as < b r / > e.t.c

    Theoretically you may do htmlentities before inserting to DB, but this might make further data processing harder, if you would need original text.

    3. See above
    

提交回复
热议问题