How can PHP developers ensure that user input is properly sanitized when working with dynamic IDs in URLs?

PHP developers can ensure that user input is properly sanitized when working with dynamic IDs in URLs by using PHP's built-in filter_var() function with the FILTER_SANITIZE_NUMBER_INT filter to ensure that the ID is an integer value. This helps prevent SQL injection attacks and other security vulnerabilities.

// Sanitize the dynamic ID parameter from the URL
$id = filter_input(INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT);

// Use the sanitized ID in your code
if ($id !== false) {
    // Proceed with using the sanitized ID
} else {
    // Handle the case where the ID is not a valid integer
}