How can the PHP header function be used effectively to ensure proper image display in different browsers?

When displaying images in a web page, it's important to set the correct content type in the HTTP header to ensure proper display in different browsers. This can be done using the PHP header function with the "Content-Type" parameter set to the appropriate image type (e.g. "image/jpeg" for JPEG images). By setting the correct content type, browsers will be able to interpret the image data correctly and display it as intended.

<?php
// Set the content type header to display a JPEG image
header('Content-Type: image/jpeg');

// Output the image data
readfile('path/to/image.jpg');
?>