Cleaning $_GET['id']

Associate
Joined
26 Jun 2003
Posts
1,140
Location
North West
I get the variable from the url to execute in queries. 'id' **** always be a number so whats the best way to clean it?

will intval do or is there sum sort of regular expressions i can do to redirect the page if the value of id is not a number?

Thx
 
Should this work?

PHP:
function validateInt($number)
{
	if (is_numeric($number))
		return intval($number);		
	return;
}
 
but if u use intval and 'id' is sumthing like: '342thisisnotanumber' it will return 342. It would still be nice if I knew this wudnt be accepted.
 
this thread turned out to be longer than expected. :eek:

I think rob wins, casting **** work fine.

Thx all
 
Back
Top Bottom