What are the potential risks of exposing image URLs to spambots in PHP?

Exposing image URLs to spambots in PHP can lead to an increased risk of hotlinking, where spambots can use your server's resources to display images on their own websites. To prevent this, you can implement a simple referrer check in your PHP code. This way, the image will only be displayed if the request comes from your own website.

<?php
// Check if the request comes from your website
$referer = $_SERVER['HTTP_REFERER'];
if(strpos($referer, 'yourwebsite.com') === false) {
    // Redirect to a default image or display an error message
    header('Location: default_image.jpg');
    exit;
}

// Display the image
$imageUrl = 'image.jpg';
echo '<img src="' . $imageUrl . '" alt="Image">';
?>