What are the best practices for securely handling user input, such as the parameter passed to the getRepLoc function in PHP?

When handling user input in PHP, it is crucial to sanitize and validate the input to prevent security vulnerabilities such as SQL injection or cross-site scripting attacks. One way to securely handle user input is to use PHP's filter_input function with appropriate filter flags to sanitize the input. Additionally, it is essential to validate the input against expected values to ensure it meets the necessary criteria.

// Securely handle user input for the getRepLoc function
$repLoc = filter_input(INPUT_GET, 'repLoc', FILTER_SANITIZE_STRING);

if ($repLoc !== false) {
    // Input is valid, proceed with the operation
    // Do something with $repLoc
} else {
    // Input is invalid, handle the error accordingly
    echo "Invalid input for repLoc";
}