Do htmlspecialchars and mysql_real_escape_string keep my PHP code safe from injection?

前端 未结 6 1223
离开以前
离开以前 2020-11-22 04:01

Earlier today a question was asked regarding input validation strategies in web apps.

The top answer, at time of writing, suggests in PHP just using

6条回答
  •  被撕碎了的回忆
    2020-11-22 04:27

    $result = "SELECT fields FROM table WHERE id = ".(INT) $_GET['id'];
    

    Works well, even better on 64 bit systems. Beware of your systems limitations on addressing large numbers though, but for database ids this works great 99% of the time.

    You should be using a single function/method for cleaning your values as well. Even if this function is just a wrapper for mysql_real_escape_string(). Why? Because one day when an exploit to your preferred method of cleaning data is found you only have to update it one place, rather than a system-wide find and replace.

提交回复
热议问题