what is a good method to sanitize the whole $_POST array in php?

后端 未结 5 1163
广开言路
广开言路 2020-12-12 21:08

I have a form with a lot of variables which is then sending an email, rather than sanitizing each $_POST value with filter_var($_POST[\'var\'], FILTER_SAN

5条回答
  •  眼角桃花
    2020-12-12 21:29

    If the type of each of your input variables is a string and you want to sanitize them all at once, you can use:

    // prevent XSS
    $_GET   = filter_input_array(INPUT_GET, FILTER_SANITIZE_STRING);
    $_POST  = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING);
    

    This will sanitize your $_GET and $_POST arrays.

    Seen here: PHP -Sanitize values of a array

提交回复
热议问题