PHP's new input_filter does not read $_GET or $_POST arrays

前端 未结 6 1488
温柔的废话
温柔的废话 2020-12-16 00:28

In PHP 5.2 there was a nice security function added called \"input_filter\", so instead of saying:

$name = $_GET[\'name\'];

you can now say

6条回答
  •  别那么骄傲
    2020-12-16 01:04

    A handy way to do this without modifying the global array:

    if (!($name = filter_input(INPUT_GET, 'name'))) {
        $name = 'default_value';
    }
    

    Or using the ternary operator:

    $name = ($name = filter_input(INPUT_GET, 'name')) ? $name : 'default_value';
    

提交回复
热议问题