Results 1 to 3 of 3

Thread: Download Logger

  1. #1
    Join Date
    Jun 2007
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Download Logger

    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

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Code:
    <?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('&#37;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']);
    ?>
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    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)
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •