What are common issues with displaying images in PHP when using GET parameters in the URL?
Common issues with displaying images in PHP when using GET parameters in the URL include not properly sanitizing the input, leading to security vulnerabilities such as directory traversal attacks. To solve this issue, it is important to validate and sanitize the input before using it to fetch and display the image.
<?php
// Sanitize the input parameter to prevent directory traversal attacks
$image_name = isset($_GET['image']) ? basename($_GET['image']) : 'default.jpg';
// Display the image
echo '<img src="images/' . $image_name . '" alt="Image">';
Keywords
Related Questions
- What is the correct syntax for accessing specific values in an associative array in PHP?
- How can one efficiently store and access multi-dimensional arrays in PHP when dealing with parent-child relationships in database query results?
- How can relative links or Base-URLs be used effectively in PHP to transfer a webpage?