requestCheck (function)

Last updated: Fri, May 26, 2023 9:15 am
Return to Knowledgebase


The requestCheck function in UserSpice is a custom function used to check and retrieve request variables from $_GET and $_POST superglobal arrays. It ensures that the expected variables are present in the request and returns them as an array. If any expec




# Parameter Data Type Required Description
1 $expectedAr array Yes An array of expected variable names.


Data Type Description of Returned Data
array The function returns an associative array containing the request variables if all expected variables are present.

Further Documentation:

$expectedVariables = ['var1', 'var2', 'var3'];

$requestVariables = requestCheck($expectedVariables);

// Process the request variables
// ...

// Access specific variables
$var1Value = $requestVariables['var1'];
$var2Value = $requestVariables['var2'];
$var3Value = $requestVariables['var3'];

In the example above, the requestCheck function is called with the $expectedVariables array as the argument, which lists the expected variable names. The function checks for the presence of the variables in the request, combining $_GET and $_POST superglobal arrays. If any expected variables are missing, the returnError function is called to generate an error response and halt the script execution.

If all expected variables are present, the function returns an associative array containing the request variables. You can then access specific variables by their respective keys in the array.

Note that the returnError function is typically called within requestCheck to handle error scenarios and provide a standardized error response format.