Author Topic: avoid hotlinking in downloads  (Read 5766 times)

0 Members and 1 Guest are viewing this topic.

Offline edu

  • Jr. Member
  • **
  • Posts: 74
    • View Profile
avoid hotlinking in downloads
« on: May 06, 2006, 12:28:05 PM »
I need a captcha system to avoid hotlinking in downloads , anybody can download (externally) any image with:

www.mydomain.com/download.php?image_id=345   or   www.mydomain.com/download.php?action=zip&image_id=345

Somebody can help me ?

Thanks.

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: avoid hotlinking in downloads
« Reply #1 on: May 06, 2006, 05:16:12 PM »
Lets try this:
in includes/functions.php find:
Code: [Select]
    $download_zip_button = ($target == "" && function_exists("gzcompress") && function_exists("crc32")) ? "<a href=\"".$site_sess->url(ROOT_PATH."download.php?action=zip&amp;".URL_IMAGE_ID."=".$image_row['image_id'])."\"".$target."><img src=\"".get_gallery_image("download_zip.gif")."\" border=\"0\" alt=\"\" /></a>" : "";
Insert below:
Code: [Select]
    $site_sess->set_session_var("download_auth", time());

Then in download.php find:
Code: [Select]
elseif ($image_id) {
Insert below:
Code: [Select]
  if (!$site_sess->get_session_var('download_auth'))
  {
    if (!function_exists("redirect")) { function redirect($url) { header("Location: ".$url); exit;}}
    redirect($url);
  }
  $site_sess->drop_session_var('download_auth');

Now, in order to download a single image, you must first visit the site. If one tryed to hotlink the download link, it will simply redirect to your site.

P.S. this should work with all 4images versions.
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline edu

  • Jr. Member
  • **
  • Posts: 74
    • View Profile
Re: avoid hotlinking in downloads
« Reply #2 on: May 16, 2006, 12:30:39 PM »
Thank you V@no !!, It work perfectly.

I would like to force the user to visit the image before he would can download it; is possible ?

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: avoid hotlinking in downloads
« Reply #3 on: May 16, 2006, 03:21:01 PM »
replase
Code: [Select]
    redirect($url);
with
Code: [Select]
    redirect($site_sess->url(ROOT_PATH."details.php?image_id=".$image_id, "&"));
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline kief24

  • Sr. Member
  • ****
  • Posts: 267
    • View Profile
Re: avoid hotlinking in downloads
« Reply #4 on: May 18, 2006, 06:59:06 PM »
works great, thx a lot !