I have a page like so:
http://sitename/gallery.php?page=2
It has pagination links at the bottom by which we can br
if (isset($_GET['page']) && (($get_page_filtered = filter_var($_GET['page'], FILTER_VALIDATE_INT)) !== FALSE) {
$get_page_int = $get_page_filtered;
}
@see https://stackoverflow.com/a/41868665/6758130
Use filter_var() with the FILTER_VALIDATE_INT
filter on it, and check the return value.
Using is_int
won't help, probably. All incoming parameters (including $_GET and $_POST) are parsed as strings by PHP. The is_int
function checks the datatype, not the value. ctype_digit
checks for only digits though:
if(isset($_GET['page']) && ctype_digit($_GET['page']){
$page = (int)$_GET['page'];
echo "Page Number: ".$page;
}