What are common pitfalls when using $_GET in PHP for image retrieval?
Common pitfalls when using $_GET in PHP for image retrieval include not validating the input properly, which can lead to security vulnerabilities such as directory traversal attacks. To solve this issue, always sanitize and validate the input before using it to retrieve images.
// Validate the input before using it for image retrieval
if(isset($_GET['image']) && preg_match("/^[a-zA-Z0-9]+\.(jpg|jpeg|png|gif)$/", $_GET['image'])) {
$image = $_GET['image'];
// Proceed with image retrieval
} else {
// Handle invalid input
echo "Invalid image file name";
}