PHP & mySQL: When exactly to use htmlentities?

后端 未结 4 1175
遥遥无期
遥遥无期 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 20:51

    In essence, you should use mysql_real_escape_string prior to database insertion (to prevent SQL injection) and then htmlentities, etc. at the point of output.

    You'll also want to apply sanity checking to all user input to ensure (for example) that numerical values are really numeric, etc. Functions such as is_int, is_float, etc. are useful at this point. (See the variable handling functions section of the PHP manual for more information on these functions and other similar ones.)

提交回复
热议问题