A PHP function to prevent SQL Injections and XSS

后端 未结 3 1783
暖寄归人
暖寄归人 2020-12-14 03:24

I am tring to make my PHP as secure as possible, and the two main things I am trying to avoid are

  • mySQL Injections
  • Cross-Side Scripting (XSS)
3条回答
  •  再見小時候
    2020-12-14 03:59

    mysql_real_escape_string() doesn't prevent XSS. It will only make impossible to do SQL injections.

    To fight XSS, you need to use htmlspecialchars() or strip_tags(). 1st will convert special chars like < to < that will show up as <, but won't be executed. 2nd just strip all tags out.

    I don't recommend to make special function to do it or even make one function to do it all, but your given example would work. I assume.

提交回复
热议问题