Created
May 2, 2012 18:03
-
-
Save birarda/2578772 to your computer and use it in GitHub Desktop.
verifyRequestParameter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function verifyRequestParameter($param, $min = null, $max = null, $send_resp = true) { | |
// make sure the parameter was passed | |
if (!array_key_exists($param, $_REQUEST)) { | |
$error_message = "Missing {$param} parameter"; | |
} else { | |
// if we have a max or min value make sure the parameter is in range | |
if (isset($min)) { | |
if ($_REQUEST[$param] < $min) { | |
$error_message = "Parameter {$param} not greater than accepted minimum value."; | |
} | |
} | |
if (isset($max)) { | |
if ($_REQUEST[$param] > $max) { | |
$error_message = "Parameter {$param} not less than accepted maximum value."; | |
} | |
} | |
} | |
// if we have an error message then send that back | |
// and return false | |
if (isset($error_message)) { | |
if ($send_resp) { | |
// only send the json response if the calling function asked us to | |
response(json_encode(array( | |
'error' => true, | |
'message' => $error_message | |
))); | |
} | |
return false; | |
} else { | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment