Block other sites from uploading my images

Asked

Viewed 49 times

-1

How do I block other domains from uploading my images?

  • What you’re looking for is a way to ban Hotlinking, look for HTTP_REFERER, there are some techniques to avoid this.

1 answer

0

A strategy for what you want, would create an intermediary page to load your images, with this you can detect the origin of the request, below I will put an example in PHP.

<?php
if(isset($_SERVER['HTTP_REFERER']) && strpos($_SERVER['HTTP_REFERER'], 'http://www.seusite.com.br') === 0 && isset($_GET['img'])){
    $name = './imagens/' . $_GET['img'];
    $fp = fopen($name, 'rb');

    header("Content-Type: " . mime_content_type($name));
    header("Content-Length: " . filesize($name));

    fpassthru($fp);
    exit;
}
?>

Example of a page using the image:

<img src="imagens.php?img=icone.jpg" />

To be more effect you have to block apache direct access to image folder and its files.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.