View Full Version : Download Logger

06-05-2007, 08:54 AM
Hey im new to php and i was wondering if someone could show me how to create a download counter for downloads on a page. It should simply log everything in a text file, and only have the file name, date it was downloaded and the ip that downloaded it. Please help me if you can.

Thanks alot

06-05-2007, 03:06 PM
$file = $_GET['file'];
if(!file_exists($file)) {
header('HTTP/1.1 404 Not Found');
die('File not found.');
$f = fopen('logfile', 'a');
fwrite($f, sprintf('&#37;s: %s downloaded %s', date('o-m-d'), $_SERVER['HTTP_REMOTE_ADDR'], $_GET['file']) . "\n");
header('HTTP/1.1 302 Found');
header('Location: http://www.yoursite.com/files/' . $_GET['file']);

06-05-2007, 05:33 PM
Link to that page like this:
<a href="that.php?file=game.exe">click</a>
would download http://www.yoursie.com/files/game.exe

('that.php' would be the code in Twey's post)