Jump to content

Recommended Posts

Is thier some code I can use to Notifiy me of files that are downloaded from my site.

I would like to put some public files (PDF) in a folder to where the public could download what ever, but I want to know who downloaded these files. Dont know much more than that just got the idea from another site cause they new I downloaded a file and I thought it would be a good idea on may site to do something like that.

Try making a htaccess redirect to a php file and have in that php file the where the page was redirected from and make a counter and then redirect them back to the file also make it so that it will only allow them download the file if they have been at the previous page.

I don't know. But what I would do it see how htaccess work and say to the htaccess when a person tries to download that file take them to thing page. Then use php to find where the page has been redirected from and then keep track of how many people have downloaded this file then use php to redirect the file and make the htaccess only allow access to the file when the use has been at the previous page with the script that tracks the download. Simple but would take some time to figure out how to make this all to work. Trial and Error is the way to go about this.

What is the requirements for them to download a file?

 

Nothing?

Email address?

Name?

 

Do you want an email, or saved to a database?

 

I suggest a database, that way you could echo the amount of downloads below the file, on the downloads page.

 

download.php

$file = $_GET['q'];
$sql = "INSERT INTO downloads (filename,count,last_time) VALUES ('$file',1,NOW())
  ON DUPLICATE KEY UPDATE count=count+1, last_time = NOW()";
mysql_query($sql);

//start file download...

 

download table

CREATE TABLE `downloads` (
  `id` int(11) NOT NULL auto_increment,
  `filename` varchar(50) NOT NULL,
  `count` int(11) NOT NULL,
  `last_time` timestamp NOT NULL default CURRENT_TIMESTAMP,
  PRIMARY KEY  (`id`),
  UNIQUE KEY `filename` (`filename`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

 

This is in the simplest form available.

What is the requirements for them to download a file?

 

Nothing?

Email address?

Name?

 

Do you want an email, or saved to a database?

 

I suggest a database, that way you could echo the amount of downloads below the file, on the downloads page.

 

download.php

$file = $_GET['q'];
$sql = "INSERT INTO downloads (filename,count,last_time) VALUES ('$file',1,NOW())
  ON DUPLICATE KEY UPDATE count=count+1, last_time = NOW()";
mysql_query($sql);

//start file download...

 

download table

CREATE TABLE `downloads` (
  `id` int(11) NOT NULL auto_increment,
  `filename` varchar(50) NOT NULL,
  `count` int(11) NOT NULL,
  `last_time` timestamp NOT NULL default CURRENT_TIMESTAMP,
  PRIMARY KEY  (`id`),
  UNIQUE KEY `filename` (`filename`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

 

This is in the simplest form available.

 

And how would I get the file? If it was at http://domain.com/file.exe I could just go to that address and download. But if you had some way of stopping that from happening. You could use htaccess to stop that but then how do you access that?

 

And how would I get the file? If it was at http://domain.com/file.exe I could just go to that address and download. But if you had some way of stopping that from happening. You could use htaccess to stop that but then how do you access that?

 

You store the files above the document root, and use a script to access them and log the downloads. There are pre-made scripts available for that purpose. No need for anything special in the .htaccess file at all.

I think I would like to have the user supply Name and email. Then log Name,  Email, IP

Im thinking that all the files I want to share should be in one folder.

The way I was going to restric the folder access was to just put an index.htm in it to redirect if a person tries to access the folder directly.

None of these file are super important but just needs a bit of effert to get

Also maybe limit download to one time by IP

 

And how would I get the file? If it was at http://domain.com/file.exe I could just go to that address and download. But if you had some way of stopping that from happening. You could use htaccess to stop that but then how do you access that?

 

You store the files above the document root, and use a script to access them and log the downloads. There are pre-made scripts available for that purpose. No need for anything special in the .htaccess file at all.

 

Well I could just use the direct link to the file. Which would be bad since you can't track that.

Here's some code I've just grabbed from my website for downloading one of the applications. It's got a max download limit inside it hence the formula with time() and the getIP() is a function I wrote to get the user's IP address.

  if ($_POST['subdownload']) {
    if ($intAppID>0) {
      $chk=mysql_query("SELECT * FROM `downloads` WHERE `dt`>'".(time()-3600*24)."' AND `ip`='".getIP()."'");
      if (mysql_num_rows($chk)<30) { //USER CAN ONLY DOWNLOAD 30 FILES IN A 24HR PERIOD
        mysql_query("INSERT INTO `downloads` (`fileid`,`type`,`ip`,`dt`) VALUES ('".$intAppID."','a','".getIP()."','".time()."')"); //TRACKING DL
        mysql_query("UPDATE general SET `count`=`count`+1 WHERE `generalid`='".$intAppID."' LIMIT 1"); //INCREASE DL COUNTER
        header("Location: files/applications/".$appFilename); //DOWNLOAD THE FILE
        exit;
      } else {
        $blnMaxedDownloads=true; //IF THIS IS SET THE USER HAS DL'D 30 FILES IN 24HRS
      }
    }
  }

 

"dt" field is INT UNSIGNED as it contains a Unix timestamp, "ip" is VARCHAR(15)

 

EDIT: Added comments to make it easier to read.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.