I am doing a pagination script and I want to give users the ability to control how many results are shown in one page. I am doing this through the use of a GET variable, like this: example.org/articles.php?count=10
. Only problem is that the GET variable must be an integer or the code spits out random errors, some of which contains information that the user should not be seeing.
Here is my code:
// Checks if there is a GET variable (this part works fine)
if (isset($_GET["count"])) {
if (!empty($_GET["count"])) {
$page_rows = $_GET["count"];
} else {
$page_rows = $page_rows_default;
}
} else {
$page_rows = $page_rows_default;
}
// checks if the GET variable is an interger
// if not, the offending value is replaced with 0
// (it doesn't work)
if(is_int($page_rows) == false) {
$page_rows = 0;
}
From my experimentation my code can tolerate zeros and negative integers, but fails hard when given something like ?count=asdf
. I mostly do not want the user to be able to crash the script by injecting random text into the GET variables. How do I get the script to automatically detect non-integer values so that they can be dealt with instead of simply halting the code?