What potential issues can arise when using $_SERVER['SERVER_NAME'] to display image paths in PHP?

Using $_SERVER['SERVER_NAME'] to display image paths in PHP can potentially lead to incorrect image paths being displayed if the server configuration is not properly set up. To ensure that the correct image paths are displayed, it is recommended to use $_SERVER['HTTP_HOST'] instead, as it provides the host name from the request header.

$image_path = 'http://' . $_SERVER['HTTP_HOST'] . '/images/image.jpg';
echo '<img src="' . $image_path . '" alt="Image">';