What is the potential issue with passing the active image ID to the img src in PHP?

Passing the active image ID directly to the img src in PHP can potentially lead to security vulnerabilities such as XSS attacks. To prevent this, it is important to properly sanitize and validate the input before using it in the img src attribute. One way to solve this issue is to store the image IDs in a secure database and retrieve them based on user input.

<?php
// Assuming $activeImageId is the user input for the active image ID
$activeImageId = $_GET['activeImageId'];

// Sanitize and validate the input
$activeImageId = filter_var($activeImageId, FILTER_SANITIZE_NUMBER_INT);

// Retrieve the image URL from a secure database based on the active image ID
$imageUrl = getImageUrlFromDatabase($activeImageId);

// Output the image using the retrieved URL
echo '<img src="' . $imageUrl . '" alt="Active Image">';
?>