big-dog1965 Posted July 31, 2010 Share Posted July 31, 2010 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. Quote Link to comment Share on other sites More sharing options...
ajicles Posted July 31, 2010 Share Posted July 31, 2010 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. Quote Link to comment Share on other sites More sharing options...
big-dog1965 Posted July 31, 2010 Author Share Posted July 31, 2010 how does that look Quote Link to comment Share on other sites More sharing options...
ajicles Posted August 1, 2010 Share Posted August 1, 2010 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. Quote Link to comment Share on other sites More sharing options...
jcbones Posted August 1, 2010 Share Posted August 1, 2010 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. Quote Link to comment Share on other sites More sharing options...
ajicles Posted August 1, 2010 Share Posted August 1, 2010 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? Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted August 1, 2010 Share Posted August 1, 2010 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. Quote Link to comment Share on other sites More sharing options...
big-dog1965 Posted August 1, 2010 Author Share Posted August 1, 2010 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 Quote Link to comment Share on other sites More sharing options...
ajicles Posted August 2, 2010 Share Posted August 2, 2010 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. Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted August 2, 2010 Share Posted August 2, 2010 No you couldn't. It would be outside of the web root, as I said. Quote Link to comment Share on other sites More sharing options...
Yesideez Posted August 2, 2010 Share Posted August 2, 2010 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.