Why is filter_input() incomplete?

后端 未结 3 1418
半阙折子戏
半阙折子戏 2021-01-02 01:18

I am working a lot on a PHP-based CMS at the moment, and while I\'m at it I would like to move all the handling and sanitation of user input to one central place. (At the mo

3条回答
  •  生来不讨喜
    2021-01-02 01:41

    In programming, you must be as restrictive on your input as possible. That goes for data sources as well. $_REQUEST contains everything in $_GET, $_POST and $_COOKIE, which may lead to problems.

    Think for example what happens if a plugin of your CMS introduces a new special key in one of them, which happens to exist as a meaningful key in another plugin?

    So DON'T ever use $_REQUEST. Use $_GET, $_POST or $_COOKIE, whichever fits your scenario. It's a good practice to be as strict as possible, and that has nothing to do with PHP, but with programming in general.

提交回复
热议问题