How can the header() function in PHP affect the display of images in different browsers?

The header() function in PHP can affect the display of images in different browsers by setting the content type of the response. If the content type is not set correctly, some browsers may not display the image properly. To ensure images are displayed correctly in all browsers, you can use the header() function to set the content type to image/jpeg or image/png before outputting the image.

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

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