public function get($item) {
if (isset($_POST[$item]) && $_POST[$item] != '') {
$_POST[$item] = filter_var($_POST[$item],FILTER_SANITIZE_SPECIAL_CHARS);
if(is_numeric($_POST[$item])) {
return (int)$_POST[$item];
}
return $_POST[$item];
}else if (isset($_GET[$item]) && $_GET[$item] != '') {
$_GET[$item] = filter_var($_GET[$item],FILTER_SANITIZE_SPECIAL_CHARS);
if(is_numeric($_GET[$item])) {
return (int)$_GET[$item];
}
return $_GET[$item];
}
return '';
}
Is there a way I can make this more efficient? And/Or can you help me improve this code? I want to check if there is value into the $_GET / $_POST array. And filter all the evil input from a bad user.
Use $_REQUEST
which contains both POST
and GET
variables.
public function get($item) {
if (!empty($_REQUEST[$item])) {
$_REQUEST[$item] = filter_var($_REQUEST[$item], FILTER_SANITIZE_SPECIAL_CHARS);
return is_numeric($_REQUEST[$item]) ? (int) $_REQUEST[$item] : $_REQUEST[$item];
}
return '';
}