What is the best practice for displaying images from the web in PHP?

When displaying images from the web in PHP, it is important to ensure that the images are fetched securely and efficiently. One common approach is to use the `file_get_contents` function to fetch the image data from a URL and then output it using appropriate headers. This allows you to display images from external sources without directly linking to them, which can help prevent hotlinking and potential security risks.

<?php

// URL of the image to display
$image_url = 'https://example.com/image.jpg';

// Fetch the image data from the URL
$image_data = file_get_contents($image_url);

// Output appropriate headers and the image data
header('Content-Type: image/jpeg');
echo $image_data;

?>