How can one prevent direct linking to images on their website and ensure that a hyperlink to the website appears below the image?
To prevent direct linking to images on a website and ensure that a hyperlink to the website appears below the image, you can use PHP to check the HTTP referer header to see if the request is coming from your website. If it is not, you can redirect the request to your homepage and display a hyperlink below the image.
<?php
// Check if request is coming from your website
if(!isset($_SERVER['HTTP_REFERER']) || strpos($_SERVER['HTTP_REFERER'], 'yourwebsite.com') === false) {
header('Location: http://yourwebsite.com');
exit;
}
?>
<!-- HTML code to display image and hyperlink below -->
<img src="image.jpg" alt="Image">
<a href="http://yourwebsite.com">Visit our website</a>