What are the potential legal implications of embedding images from external sites without permission on a PHP-based website?

Embedding images from external sites without permission on a PHP-based website can potentially lead to copyright infringement issues. To avoid legal implications, it is important to either obtain permission from the image owner or use images that are labeled for reuse.

<?php
// Example code to fetch and display an image from an external site with permission

$image_url = 'https://www.example.com/image.jpg'; // Replace with the actual image URL

// Check if the image URL is allowed to be embedded
$allowed_domains = array('example.com', 'anotherexample.com');
$parsed_url = parse_url($image_url);
if (in_array($parsed_url['host'], $allowed_domains)) {
    echo '<img src="' . $image_url . '" alt="Image">';
} else {
    echo 'Image cannot be displayed due to copyright restrictions.';
}
?>