I have a page like so:
http://sitename/gallery.php?page=2
It has pagination links at the bottom by which we can browse. Everytime the page numbers are clicked, it would send a GET request with parameters page=1 or page=2 and so on ...
When I store these values to $page from teh $_GET variable, it is a string value. I can convert it to an integer using (int) like this:
if(!empty($_GET['page'])){
$page = (int)$_GET['page'];
echo "Page Number: ".$page;
}
But how can I make sure that the value passed is an integer only and not other crap?
var_dump()int) as the value ofpage? Other than that you don't need to check it's type... Not that I'm against asking the question - just questioning the use in this case... knowledge for knowledge's sake is always good :)$pagevariable after you have cast to an int - you need not worry about malicious content... because anything that isn't numeric will be cast to 0.echo (int) '//*&73...\\made_up_nonsense...!'; #will echo 0. It's good to be thinking in this regard however ;) you will not believe the number of scripts out there that allow anything to be passed in and used in scary ways...