Answer the question
In order to leave comments, you need to log in
What about is_numeric() if it skips spaces?
Hello everyone :)
In general, there is such a story. I decided to check GET parameters for numbers, and then I got carried away.
I started digging and realized that if you pass a string with spaces and a number as a GET parameter in the url, then is_numeric () eats it and spits out true. And I wouldn't want that to happen. Of course, now I've decided everything like this:
$key_from_get = isset($_GET["key"]) ? $_GET["key"] : "";
$iin_from_get = isset($_GET["iin"]) ? $_GET["iin"] : "";
$key = str_replace(' ', '', $key_from_get);
$iin = str_replace(' ', '', $iin_from_get);
if(is_numeric($key) && is_numeric($iin)){
TrekInfo($key,$iin); // Отправляем данные в API
}
else{
echo 'Упс! Что-то не так с параметрами запроса!';
}
Answer the question
In order to leave comments, you need to log in
If you expect only numbers and they cannot be null, you can cast the parameters to integer.
$key = isset($_GET['key']) ? (int)$_GET['key'] : null;
$iin = isset($_GET['iin']) ? (int)$_GET['iin'] : null;
if(!empty($key) && !empty($iin)) {
TrekInfo($key, $iin); // Отправляем данные в API
} else {
echo 'Упс! Что-то не так с параметрами запроса!';
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question