I want a dead simple generic $_GET-vars validator, and don’t have any desire to reinvent the wheel.
Is there any solid and simple script I can use, something like:
function secure($varName,$format = 'int') {
//format: boolean,int,dec,str,date
//add stripslashes if mq
$var = $_GET[$varName];
switch($format) {
case 'int':
$r = floor($var);
break;
case 'boolean':
$r = ($var === true);
break;
case 'dec':
$r = preg_replace("/0-9.-/i", "", $val);
break;
case 'str':
..
case 'date':
//ISO 8601 is enough...
}
regards,
//t
filter_input()comes fairly close to what you want to do.It’s got a decent number of validation and sanitation filters.
An example stolen from the manual: