What are some best practices for handling query string parameters in PHP scripts for web development purposes?

When handling query string parameters in PHP scripts for web development, it is important to properly sanitize and validate the input to prevent security vulnerabilities such as SQL injection or cross-site scripting attacks. One common best practice is to use the filter_input() function to retrieve and sanitize query string parameters.

// Retrieve and sanitize query string parameter 'id'
$id = filter_input(INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT);

// Check if 'id' parameter is valid
if($id === false) {
    // Handle invalid input
    echo "Invalid parameter value";
} else {
    // Use the sanitized 'id' parameter in your script
    echo "ID: " . $id;
}