Joined: Aug 27, 2002 Posts: 16976 Location: Kansas
Posted:
Tue Oct 07, 2003 11:18 am
As you know, I offer a hack to the Downloads module that allows you to protect/restrict certain files to registered users only. Well, what if you want to allow all visitors to see the downloads but only registered users to actually download them? Very simple! Find the function getit() in modules/Downloads/index.php. It looks like this
Code:
function getit($lid) {
global $prefix, $dbi;
sql_query("update ".$prefix."_downloads_downloads set hits=hits+1 WHERE lid=$lid", $dbi);
$result = sql_query("SELECT url FROM ".$prefix."_downloads_downloads WHERE lid=$lid", $dbi);
list($url) = sql_fetch_row($result, $dbi);
Header("Location: $url");
}
Modify it to this
Code:
function getit($lid) {
global $prefix, $dbi, $user, $admin;
if (!is_admin($admin)&&!is_user($user)) {
$pagetitle = "- "._ACCESSDENIED."";
include("header.php");
title("$sitename: "._ACCESSDENIED."");
OpenTable();
echo "<center><b>"._RESTRICTEDAREA."</b><br><br>"
.""._MODULEUSERS.""
.""._GOBACK."";
CloseTable();
include("footer.php");
die();
}
sql_query("update ".$prefix."_downloads_downloads set hits=hits+1 WHERE lid=$lid", $dbi);
$result = sql_query("SELECT url FROM ".$prefix."_downloads_downloads WHERE lid=$lid", $dbi);
list($url) = sql_fetch_row($result, $dbi);
Header("Location: $url");
}
Let me ask this... does this stop people from putting the link to a download in a forum on another site somewhere and the dl box from popping up when it is clicked on? I guess does this stop hotlinking? I may be chasing this question in several threads but I can't figure out if they are all the same question... thanks for your patience...
Joined: Aug 27, 2002 Posts: 16976 Location: Kansas
Posted:
Mon Oct 20, 2003 11:00 am
This allows members only to download, via nuke. If they are using the nuke system to access the downloads then this will stop them unless they are registered. This will not stop anyone from directly accessing the files, aka hotlinking. Try a search on google for 'stop hot linking php'. Several hits come back. Here is a good one
Only registered users can see links on this board! Get registered or login to the forums!
As I said in an earlier post, I think it can be more easily implemented by cross referencing the referer IP with your IP/domain name.
BTW, you can also use your cPanel. Towards the bottom is an icon labeled Hot Link Protection I haven't used it (yet) but you might want to play with it!
Joined: Aug 27, 2002 Posts: 16976 Location: Kansas
Posted:
Sat Dec 20, 2003 11:01 am
The way this works is as follows. When you add a download, it is assigned a counter/id and is referenced in the table as 'lid'. For example, when you mouse over the links in your download modules, you will see the lid=1 in the browser status bar. So, the first download you add has an 'lid' of 1. If you add a line like this to my code
$lidArray[] = 1;
then visitors will be able to view the download but must be registered to actually download it. You add more lines like that as you want to restrict more downloads. Does that clear it up?
Joined: Aug 27, 2002 Posts: 16976 Location: Kansas
Posted:
Sat Dec 20, 2003 11:52 am
This code is specific to nuke but the methodology can certainly be extrapolated to other situations. But, it can only work where the user is not directly accessing the link, but only an id (like lid) to the link.
Last edited by Raven on Wed Dec 24, 2003 1:39 pm; edited 1 time in total
I have a link or a submit button.. When registered members click the link, they're taken to another page. When they click the submit button, they'll put info into a database.
Now when visitors click these same links/buttons, I want them to see the "create a new account" message. Is this possible?
Instead of posting direct download links post links for the details view. This might also encourage people to vote once in a while But don't hold your breathe on that one. Then if you want to flash some ads at them or anything like that theres your chance.
Raven, I got a parse error until I took out the last } then it worked allowing me to see the downloads but not download because I wasn't registered. the problem is now though the fetch mod does not kick in once I log-in... it seems I cannot have both with the way I have done it. Can oyu help please? Thank you.
Looks like your code to change is split up into the fetch.php
Code:
<?php
include("mainfile.php");
if ($fetchid == "") {
header("location: index.php");
}
if ($checkpass == $passcode) {
$url = base64_decode($fetchid);
if (ereg ("http", $url, $location)) {
/* Increase the counter for total downloads */
[b] sql_query("update ".$prefix."_downloads_downloads set hits=hits+1 where lid=$lid", $dbi);
header("location: $url");
exit;[/b] }
if (file_exists($url)) {
/* Fetch the file if it exists */
/* Increase the counter for total downloads */
sql_query("update ".$prefix."_downloads_downloads set hits=hits+1 where lid=$lid", $dbi);
header("location: $url");
exit;
} else {
cookiedecode($user);
$username = $cookie[1];
if ($username == "") {
$username = "Guest";
}
$date = date("M d, Y g:i:a");
/* Flag it for being a broken link if it isn't found */
sql_query("insert into ".$prefix."_downloads_modrequest values (NULL, $lid, 0, 0, '', '', '', 'Download Script<br>$date', 1, '$auth_name', '$email', '$filesize', '$version', '$homepage')", $dbi);
include("header.php");
OpenTable();
echo "<center><font class=\"title\">File Not Found for $title</font></center>";
CloseTable();
echo "<br>";
OpenTable();
echo "<p>Sorry $username, The file for <b>\"$title\"</b> was not found. It
could be because the person hosting the download may removed or renamed the
file.</p>
<p>This download has now been automatically flagged for review by the
webmaster.</p>
<center>[ <a href=\"downloads.html\">Back To Downloads</a> ]</center>";
CloseTable();
echo "<br>";
OpenTable();
echo "<div align=\"right\"><font class=\"tiny\">Fetching Mod V.1b<br>By:
<a href=\"http://www.2thextreme.org\">MGCJerry</a></div>";
CloseTable();
include("footer.php");
return;
}
} else {
include("header.php");
OpenTable();
echo "<center><font class=\"title\">Password Error</font></center><br><br>
<p>You have entered an invalid Password.</p>
<input type=\"button\" value=\"<< Try Again\" onclick=\"history.go(-1)\">";
CloseTable();
echo "<br>";
OpenTable();
echo "<div align=\"right\"><font class=\"tiny\">Fetching Mod V.1b<br>By:
<a href=\"http://www.2thextreme.org\">MGCJerry</a></div>";
CloseTable();
Joined: Aug 27, 2002 Posts: 16976 Location: Kansas
Posted:
Thu Apr 22, 2004 8:10 am
No. Here is my getit() function. Now I do things that are usually most expedient for me
Code:
function getit($lid) {
// Add a new line of code for each $lid to block for Registered Users only
$lidArray[] = xx;
$lidArray[] = yy;
$lidArray[] = zz;
$lid = intval($lid);
$hits = intval($hits);
global $prefix, $dbi, $user, $admin, $module_name;
if (!is_user($user)&&in_array($lid,$lidArray)&&!is_admin($admin)) {
$pagetitle = "- "._ACCESSDENIED."";
include("header.php");
title("$sitename: "._ACCESSDENIED."");
OpenTable();
echo "<center><b>"._RESTRICTEDAREA."</b><br><br>"
.""._MODULEUSERS.""
.""._GOBACK."";
CloseTable();
include("footer.php");
die();
}
OpenTable();
echo "<center><font class=\"title\">Downloading $title</font></center>";
CloseTable();
echo "<br>\n";
OpenTable();
echo "<p>You have selected to download <b>$title</b></p><p><b>IMPORTANT:</b> Because my site is getting harvested by some other sites I have adopted this new system.</p>
<p>I am sorry for the inconvenience, but it is a shame that I need to use such a system because
of some users.</p>";
CloseTable();
echo "<br>\n";
OpenTable();
echo "<p><b>Directions:</b> To download the file "<b>$title</b>",
you need to retype the displayed password (there are no numbers, only letters),
and click "Fetch It". In a few moments you will receive
the download dialog or you will be directed to the appropriate site.<br /><br /><font style=\"color:red;font-weight:bold;\">In an effort to thwart bandwidth theft, I have implemented measures to ensure that the download requests are only processed from my site. This mechanism is not compatible with all anti-virus software, download accelerators, and proxies. If you make it through to the download request screen and then get a Forbidden message, the chances are it is a result of one of the three things just mentioned. In that case, you will have to temporarily disable or tweak the settings for those applications to allow the download.</font></p>
Raven I was showing you the code from the other fetch it mod and that the code you had said to replace was split up between the index.php file and the fetch.php file from it. I did not mean to offend... What would I have to do to use your code? IE what are the instructions to install it? Thanks!
View next topic View previous topic
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum