I'm trying to retrieve some GET data and filter it to make sure it contains an integer. The url string is events.php?id=22&month=2
, but when I try to get either variable filter_input
returns NULL
for some reason, I can't figure out why. This is my code:
if(!isset($pageId)) {
$pageId = filter_input(INPUT_GET, 'id', FITER_VALIDATE_INT) ?: 4;
}
if(!isset($month)) {
$month = filter_input(INPUT_GET, 'month', FITER_VALIDATE_INT) ?: date('n');
var_dump($_SERVER['QUERY_STRING'], filter_input(INPUT_GET, 'month', FITER_VALIDATE_INT));
}
The var_dump
returns string(13) "id=22&month=2" NULL
. I've also tried var_dump($_GET)
and get back array(2) { ["id"]=> string(2) "22" ["month"]=> string(1) "2" }
as expected.
Why is the filter_input
returning NULL
? I've never had a problem retrieving GET
data this way.
FITER_VALIDATE_INT
should be FILTER_VALIDATE_INT
. You are missing L
in FILTER
in all instances of the constant. Turning on error reporting would have thrown several Notice: Use of undefined constant FITER_VALIDATE_INT - assumed 'FITER_VALIDATE_INT'
errors.