View Full Version : Download Logger
quantumkangaroo
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
<?php
$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('%s: %s downloaded %s', date('o-m-d'), $_SERVER['HTTP_REMOTE_ADDR'], $_GET['file']) . "\n");
fclose($f);
header('HTTP/1.1 302 Found');
header('Location: http://www.yoursite.com/files/' . $_GET['file']);
?>
djr33
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)
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.