How can PHP GET parameters be properly handled to ensure correct functionality of a calendar script?

When handling PHP GET parameters in a calendar script, it is important to properly sanitize and validate the input to prevent any malicious attacks or unexpected behavior. One way to ensure correct functionality is to use PHP's filter_input function to retrieve and sanitize the GET parameters before using them in the script.

// Retrieve and sanitize the GET parameters for the calendar script
$year = filter_input(INPUT_GET, 'year', FILTER_VALIDATE_INT);
$month = filter_input(INPUT_GET, 'month', FILTER_VALIDATE_INT);

// Check if the parameters are valid
if ($year && $month) {
    // Calendar script logic here
    echo "Year: $year, Month: $month";
} else {
    // Handle invalid parameters
    echo "Invalid parameters";
}