So the problem / error:
filter_input () does not work with INPUT_SERVER or INPUT_ENV when you use FASTCGI
The mistake has been known for years, and I did not find anything to say about it. I found several workarounds, but did not have a complete solution, so I applied the best work in this helper function to solve the whole project. To provide some level of security and avoid train debris, the function returns to filter_var (), where filter_input () fails. It uses the same format as the built-in filter_input () function for easy integration into projects and simple subsequent deletion if the error is fixed.
function filter_input_fix ($type, $variable_name, $filter = FILTER_DEFAULT, $options = NULL ) { $checkTypes =[ INPUT_GET, INPUT_POST, INPUT_COOKIE ]; if ($options === NULL) { // No idea if this should be here or not // Maybe someone could let me know if this should be removed? $options = FILTER_NULL_ON_FAILURE; } if (in_array($type, $checkTypes) || filter_has_var($type, $variable_name)) { return filter_input($type, $variable_name, $filter, $options); } else if ($type == INPUT_SERVER && isset($_SERVER[$variable_name])) { return filter_var($_SERVER[$variable_name], $filter, $options); } else if ($type == INPUT_ENV && isset($_ENV[$variable_name])) { return filter_var($_ENV[$variable_name], $filter, $options); } else { return NULL; } }
This seems like the best solution. Please let me know if it contains errors that may cause problems.
source share