Search code examples
phphotlinking

How to show image hidding its direct link in php?


How can I create a php code that will process an ID for example and return corresponding image without providing client with actual image hotlink.

As implemented on link below the image is displayed in html page, but the hot link is hidden from client. Even opening the image in new window same link is shown not the original link to image.

This is definitely not implemented in .htaccess file as for each image URL with id corresponding image is rendered and is not a redirect to a single page.

http://www.imagesup.net/?di=15140291437113


Solution

  • a basic way could be something like this

    <?php
    
        // query to database mabye?
        $myPath = getImagePath($_GET['id']);
    
        // what kind of image file is that?
        $contentType = getContentType($myPath);
    
        // read file content
        $img = file_get_contents($myPath);
    
        // here you tell the browser what kind of image is that e.g. jpeg,png,gif...
        header("Content-Type: $contentType");
    
        echo $img;
    
    ?>
    

    you need to define getImagePath and getContentType functions according to your needs.