Why is better to use filter_input()?

后端 未结 3 782
梦谈多话
梦谈多话 2020-12-16 11:46

This should be a elementary question but why is better to use something like this:

$pwd = filter_input(INPUT_POST, \'pwd\');

Instead of jus

相关标签:
3条回答
  • 2020-12-16 12:10

    It is not better.

    Please see docs on filter_input http://www.php.net//manual/en/function.filter-input.php

    and click the "Types of Filters" link. http://www.php.net/manual/en/filter.filters.php

    I have only ever used the integer filter ...

    $user_id = filter_input(INPUT_POST, 'user_id', FILTER_SANITIZE_NUMBER_INT);
    $user = abs($user_id); // To get rid of any +/-
    
    0 讨论(0)
  • 2020-12-16 12:12

    It's not. $_GET, $_POST, $_COOKIE and $_REQUEST are filtered with default filter. filter_input(INPUT_POST, 'pwd') without additional parameters also uses the default filter. So there is no difference at all.

    0 讨论(0)
  • 2020-12-16 12:19

    Any data which is sent from the client (such as POST data) should be sanitized and escaped (and even better, sanity-checked) to ensure that it isn't going to kill your website.

    SQL Injection and Cross-site scripting are the two largest threats for failing to sanitize your user-sent data.

    0 讨论(0)
提交回复
热议问题