update page now

Voting

: max(five, four)?
(Example: nine)

The Note You're Voting On

theking2(at)king(dot)ma
2 years ago
A more generic parameter checking:

<?php
/**
 * Check if all required parameters are present in the request
 *
 * @param  mixed $request any of $_GET, $_POST, $_REQUEST
 * @param  mixed $required array of required parameters
 * @return bool true if all required parameters are present
 */
function check_params( array $request, array $required ): bool
{
    $check = array_intersect( array_keys( $request ), $required );
    return count( $check ) === count( $required );
}
?>

Use this like
<?php
if( !check_params( $_GET, ['cust_id','prod_id'] ) {
    header( "HTTP/1.1 400 Bad Request" );
    echo "Bad Request";
    exit();
}
?>

Let me know if something is build in PHP already...

<< Back to user notes page

To Top