[SNIPPET] No Hotlinking Warning

Mixed forum with phpBB code snippets
Guides and styles

[SNIPPET] No Hotlinking Warning

Post by Stoker »

No Hotlinking Warning

In ACP -> Attachments settings you can enable secure download.
Then when an image is hotlinked, nothing will show up. Just a broken image icon.
If its a file and the link is clicked, users will go to your site and see a page with this text: You are not authorised to view, download or link from/to this site.

I like to display an image that replaces the image users try to hotlink:
Image

If secure downloads is enabled, you can achieve this by a single core edit.

Open download/file.php

Find:

Code: Select all

else if (!download_allowed())
{
	send_status_line(403, 'Forbidden');
	trigger_error($user->lang['LINKAGE_FORBIDDEN']);
}
Replace with:

Code: Select all

else if (!download_allowed())
{
    // Send “403 Forbidden” status so browsers know it's a valid image response
    send_status_line(403, 'Forbidden');

    // Serve the warning image instead of the broken icon
    header('Content-Type: image/jpg');
    header('Cache-Control: public, max-age=86400'); // cache for 1 day
    readfile($phpbb_root_path . 'images/stop.jpg');
    exit;
}
Last step is to upload an image named stop.jpg to your images folder.

Now your stop.jpg will display when images are hotlinked from a non whitelisted domain.
Hotlinked files will redirect to the stop.jpg on your site

[SNIPPET] No Hotlinking Warning

Post by Steve »

test hotlink internally:
PhpBB3-BBCodes-Home.png
PhpBB3-BBCodes-Community.png
You do not have the required permissions to view the files attached to this post.