Log in

View Full Version : download page with anti-hotlinking and track counter.. not working..



BLiZZaRD
11-05-2007, 01:59 AM
I am trying to make a custom download page. Seems pretty simple. A link on my HTML page (index.html) that goes to a php page that is supposed to auto download the file. But it's not working.

Here are the scripts:

downloads.php


<?php
/*
This download script can send an email and/or log the download
There are two variables below - one for the email address and one for a download log file
Set both vraiables to the values you want
If you do not want either an email or log entry, comment out the respective line
So for example of you do not want an email sent, put a // in front of the $emailAddress line - same for the $downloadLogFile line
*/
//$emailAddress = "mail@yourdomain.com";
$downloadLogFile = "downloads.dat";
$directory = "/FrozenCoyoteLabs/Flash/Programs"; // the relative directory that has the downloads - can be ./ for the current directory
putenv('TZ=EST5EDT'); // eastern time
// nothing should be changed below this line
$filename = $_GET['file'];
$path = "$directory$filename";
if(file_exists($path) AND substr_count($filename,"/") == "0") {
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=$filename");
header("Content-Length: ".filesize($path));
readfile("$path");
if (isset($emailAddress)) {
$message = "File name: " . $filename . "\n\n";
$message .= "Time of the download: " . date(" F d h:ia") . "\n\n";
$message .= "Browser: " . $_SERVER['HTTP_USER_AGENT'] . "\n\n";
$message .= "Page Requested: " . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . "\n\n";
$message .= "Referer: " . $_SERVER['HTTP_REFERER'] . "\n\n";
$message .= "IP Address: ". $_SERVER['REMOTE_ADDR'] . "\n\n";
$message .= "Hostname: " . gethostbyaddr($_SERVER['REMOTE_ADDR']) . "\n\n";
mail($emailAddress,"Download notification",$message, "From: Website <>");
}
if (isset($downloadLogFile)) {
$downloadLogRecord = $filename . "||" . $_SERVER['REMOTE_ADDR'] . "||" . gethostbyaddr($_SERVER['REMOTE_ADDR']) . "||" . date('Y-m-d H:i:s') . "\r\n";
$file_pointer = fopen($downloadLogFile,"a");
fwrite($file_pointer,$downloadLogRecord);
fclose($file_pointer);
}
}
?>



Now when I go to this page through the html link i get "download.php?file=filename.zip" in the URL. but it's a blank page with "done" in the status bar and filename.zip does not download. ideas?

thetestingsite
11-05-2007, 02:02 AM
What if you put an extra slash at the end of this line:



$directory = "/FrozenCoyoteLabs/Flash/Programs/"; // the relative directory that has the downloads - can be ./ for the current directory


That would be the only thing that I can think of.
Hope this helps.

BLiZZaRD
11-05-2007, 02:28 AM
Tried that. it started that way. Same thing. I have also done absolute URLs and ./ directories and everything.

Perhaps it helps to mention this is NOT at root: /public_html/files here <~~ no

instead, they are in folders in folders in folders...

/public_html/1stfolder/2ndfolder/3rdfolder/files here <~~ yes

Maybe that has something to do with it?

I feel I am missing something easy as well...

tech_support
11-05-2007, 10:28 AM
Try removing the first slash:



$directory = "FrozenCoyoteLabs/Flash/Programs";

BLiZZaRD
11-05-2007, 01:45 PM
Nope.. doesn't work either. I even just tried redoing the whole thing in the /root/ folder instead of 3 levels down and it still didn't do anything. No errors, no log created no file downloaded.

I guess I will have to make my own. I think I would like that anyway.. make it more "me" more personal.. more annoying.. yeah... that's what I'll do. :D


Of course I just made us ALL look stupid. This is the hint to actually READ the comment tags. (//relative path...) should be /home/usr/server/path/to/file/

God I feel like an idiot!

insanemonkey
11-06-2007, 05:49 PM
<?php

$pages = Array(


'myzipfile.zip' => 'zipfiles/yourfilehere.zip',

'error' => 'index.php',

);

if (isset($_GET['page']) && array_key_exists($_GET['page'],$pages)) {
include($pages[$_GET['page']]);
}
?>

you can change the page to like zip
mydomain.com/index.php?zd=yourfile.zip
this should work, try using arrays.. in a away then when the array is clicked have it put a counting system or something whatever you are trying to do,
also, I am a beginner dso i dont know how if this will work

boogyman
11-06-2007, 06:12 PM
Of course I just made us ALL look stupid. This is the hint to actually READ the comment tags. (//relative path...) should be /home/usr/server/path/to/file/

God I feel like an idiot!

thats not as uncommon as you think. I have had this "brain fart" if you will a couple times before

tech_support
11-07-2007, 05:24 AM
<?php

$pages = Array(


'myzipfile.zip' => 'zipfiles/yourfilehere.zip',

'error' => 'index.php',

);

if (isset($_GET['page']) && array_key_exists($_GET['page'],$pages)) {
include($pages[$_GET['page']]);
}
?>

you can change the page to like zip
mydomain.com/index.php?zd=yourfile.zip
this should work, try using arrays.. in a away then when the array is clicked have it put a counting system or something whatever you are trying to do,
also, I am a beginner dso i dont know how if this will work
You can't include a ZIP file.
(Well, unless you want complete rubbish appearing on your screen)

djr33
11-07-2007, 09:12 AM
readfile() sends that directly to the output buffer.