download counter?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • devospice

    download counter?

    Hi,

    I'm trying to create a download counter for individual files on a web
    site and I'm not sure how to do this. Right now I'm using Webalizer
    to just read the log files and see how many times the files I'm
    interested in were downloaded. The problem is Webalizer breaks it up
    by month and I want a running total. I'd also like to see the counts
    without having to log in to Webalizer in the first place. Not that
    logging in or adding the results is too difficult, but it would be
    nice if I could just put a little number on the web site so when I go
    to the site I can imediately see the download counts.

    The first thing I thought of was accessing the log files via PHP and
    reading the data out of there. However because the log files get
    broken up, zipped, and a new one started after they reach a certain
    size I'm afraid this will be too complicated and may put too much
    extra strain on the server if this is done too often.

    Also, what's the best way to read log files with PHP anyway?

    Any ideas?

    Thanks.

    ->Later.....Spic e

  • lorento

    #2
    Re: download counter?

    I think you can make simple php application for count the download,
    like:
    when people click http://host/download.php?file=xyz.zip, the
    download.php will increase the counter and the people will forwarded
    into file xyz.zip

    these are not the code but the algorithm:
    1. create mysql table
    create table counter (filename varchar(100), counter int);
    insert into counter values ('xyz.zip', 0);
    2. create download.php file:
    //increase the counter table
    update counter set counter = counter + 1 where filename like
    '$_GET[file]'
    //forward to file
    header ("location: xyz.zip");

    ----
    http://www.mastervb.net/phpbooks -- recommended php books
    http://ascii.mastervb.net -- ascii art generator

    On Feb 8, 3:02 am, "devospice" <s...@suddendea th.orgwrote:
    Hi,
    >
    I'm trying to create a download counter for individual files on a web
    site and I'm not sure how to do this. Right now I'm using Webalizer
    to just read the log files and see how many times the files I'm
    interested in were downloaded. The problem is Webalizer breaks it up
    by month and I want a running total. I'd also like to see the counts
    without having to log in to Webalizer in the first place. Not that
    logging in or adding the results is too difficult, but it would be
    nice if I could just put a little number on the web site so when I go
    to the site I can imediately see the download counts.
    >
    The first thing I thought of was accessing the log files via PHP and
    reading the data out of there. However because the log files get
    broken up, zipped, and a new one started after they reach a certain
    size I'm afraid this will be too complicated and may put too much
    extra strain on the server if this is done too often.
    >
    Also, what's the best way to read log files with PHP anyway?
    >
    Any ideas?
    >
    Thanks.
    >
    ->Later.....Spic e

    Comment

    • Petr Vileta

      #3
      Re: download counter?

      "lorento" <laurente1234@y ahoo.compíse v diskusním príspevku
      news:1170907412 .690300.77580@j 27g2000cwj.goog legroups.com...
      >I think you can make simple php application for count the download,
      like:
      when people click http://host/download.php?file=xyz.zip, the
      download.php will increase the counter and the people will forwarded
      into file xyz.zip
      >
      these are not the code but the algorithm:
      1. create mysql table
      create table counter (filename varchar(100), counter int);
      insert into counter values ('xyz.zip', 0);
      2. create download.php file:
      //increase the counter table
      update counter set counter = counter + 1 where filename like
      '$_GET[file]'
      //forward to file
      header ("location: xyz.zip");
      >
      Better then redirecting is to read file in php script, send to browser and
      write to sql table after a file is complete send.

      1. open file
      2. read file and send to browser until EOF
      3. increase counter in DB

      This avoid a situation when user cancel download.
      --

      Petr Vileta, Czech republic
      (My server rejects all messages from Yahoo and Hotmail. Send me your mail
      from another non-spammer site please.)



      Comment

      • devospice

        #4
        Re: download counter?

        On Feb 7, 11:03 pm, "lorento" <laurente1...@y ahoo.comwrote:
        I think you can make simple php application for count the download,
        like:
        when people clickhttp://host/download.php?fi le=xyz.zip, the
        download.php will increase the counter and the people will forwarded
        into file xyz.zip
        That's what I'm doing for some other files on the site. I'm just
        storing the count in a MySQL table.

        I can't do that with these files though, because they're MP3s from a
        podcast. I can do that with the direct links on the web page, but
        people who download the files via iTunes will bypass that link. And
        changing the RSS feed to point to the PHP page instead of the MP3 page
        breaks iTunes.

        - Tom

        Comment

        • devospice

          #5
          Re: download counter?

          Better then redirecting is to read file in php script, send to browser and
          write to sql table after a file is complete send.
          >
          1. open file
          2. read file and send to browser until EOF
          3. increase counter in DB
          Just in case you don't see my other reply, the problem with this is
          it's a podcast. And pointing the RSS feed to a PHP document instead
          of directly at the MP3 breaks iTunes.

          - Tom

          Comment

          • Rik

            #6
            Re: download counter?

            On Fri, 09 Feb 2007 16:33:48 +0100, devospice <spice@suddende ath.org
            wrote:
            On Feb 7, 11:03 pm, "lorento" <laurente1...@y ahoo.comwrote:
            >I think you can make simple php application for count the download,
            >like:
            >when people clickhttp://host/download.php?fi le=xyz.zip, the
            >download.php will increase the counter and the people will forwarded
            >into file xyz.zip
            >
            That's what I'm doing for some other files on the site. I'm just
            storing the count in a MySQL table.
            >
            I can't do that with these files though, because they're MP3s from a
            podcast. I can do that with the direct links on the web page, but
            people who download the files via iTunes will bypass that link. And
            changing the RSS feed to point to the PHP page instead of the MP3 page
            breaks iTunes.
            Why does it break things? It shouldn't.

            Then again, maybe an easier solution is just to parse the access log of
            the server. Or maybe a javascript counter, allthough somewhat unreliable..
            --
            Rik Wasmus

            Comment

            • Jerry Stuckle

              #7
              Re: download counter?

              devospice wrote:
              >Better then redirecting is to read file in php script, send to browser and
              >write to sql table after a file is complete send.
              >>
              >1. open file
              >2. read file and send to browser until EOF
              >3. increase counter in DB
              >
              Just in case you don't see my other reply, the problem with this is
              it's a podcast. And pointing the RSS feed to a PHP document instead
              of directly at the MP3 breaks iTunes.
              >
              - Tom
              >
              Tom,

              It shouldn't if you send the correct header information. The fact it's
              coming from PHP should be completely transparent.

              --
              =============== ===
              Remove the "x" from my email address
              Jerry Stuckle
              JDS Computer Training Corp.
              jstucklex@attgl obal.net
              =============== ===

              Comment

              • devospice

                #8
                Re: download counter?

                It shouldn't if you send the correct header information. The fact it's
                coming from PHP should be completely transparent.
                It is. The PHP feed works fine. (http://www.thefump.com/cast.php)
                But pointing the link tag to a PHP file instead of an audio file
                generates a "this feed is not valid" error in iTunes.

                ->Later.....Spic e

                Comment

                • devospice

                  #9
                  Re: download counter?

                  Why does it break things? It shouldn't.

                  The link tag has to point to an MP3 or AAC file in order for iTunes to
                  recognize it and allow the download. Otherwise it assumes you
                  accidentally tried to subscribe to a non-audio based RSS feed, like a
                  news service or something. The PHP feed works fine. But the link has
                  to be to an audio file.

                  ->Later.....Spic e

                  Comment

                  • Jerry Stuckle

                    #10
                    Re: download counter?

                    devospice wrote:
                    >It shouldn't if you send the correct header information. The fact it's
                    >coming from PHP should be completely transparent.
                    >
                    It is. The PHP feed works fine. (http://www.thefump.com/cast.php)
                    But pointing the link tag to a PHP file instead of an audio file
                    generates a "this feed is not valid" error in iTunes.
                    >
                    ->Later.....Spic e
                    >
                    As I said - if the header is correct, it should be OK.

                    I looked at your link, but I didn't see any php files being pointed to -
                    just the mp3 files themselves.

                    I still suspect you're not sending the correct info in the header,
                    especially the content header. But you haven't shown us any code or
                    your php buffering.

                    Browsers are pretty loose about things. iTunes might be more stringent.

                    Of course, it's possible they could be looking at the file extension
                    instead of the content header. But that's defeating the purpose of the
                    header - and pretty stupid, IMHO. But it's still possible.

                    --
                    =============== ===
                    Remove the "x" from my email address
                    Jerry Stuckle
                    JDS Computer Training Corp.
                    jstucklex@attgl obal.net
                    =============== ===

                    Comment

                    • devospice

                      #11
                      Re: download counter?

                      It is. The PHP feed works fine. (http://www.thefump.com/cast.php)
                      But pointing the link tag to a PHP file instead of an audio file
                      generates a "this feed is not valid" error in iTunes.
                      >
                      ->Later.....Spic e
                      >
                      As I said - if the header is correct, it should be OK.
                      >
                      I looked at your link, but I didn't see any php files being pointed to -
                      just the mp3 files themselves.
                      Sorry. Here's the code for the feed. It pulls the most recent 5
                      entries from the database (ignoring future ones that haven't gone live
                      yet) and formats it. It's based on the code I use to update my Manic
                      Mondays podcast (http://www.suddendeath.org/cast/feed.xml) which I've
                      never had a problem with. But those always point directly to the MP3
                      file.

                      ->Later.....Spic e

                      <?php

                      // NOTE: All links point to the site folder, which must be changed
                      upon launch.

                      include("functi ons.php");

                      // Get the 5 most recent fumps.
                      $today = date("Y-m-d");
                      $fumpSQL = "SELECT * FROM fumps WHERE date<=CURDATE() ORDER BY date
                      DESC LIMIT 5";
                      $allFumps = getDataFromTabl e($fumpSQL);

                      // Calculate the last build date.
                      $lastFump = $allFumps[0];
                      $lastDate = $lastFump["date"]; // YYYY-MM-DD
                      $timestamp = strtotime($last Date);
                      $latestBuildDat e = date("D, d M Y", $timestamp);

                      echo "<?xml version=\"1.0\" ?>\r\n";
                      echo "<rss xmlns:itunes=\" http://www.itunes.com/DTDs/Podcast-1.0.dtd\"
                      version=\"2.0\" >\r\n";
                      echo "<channel>\r\n" ;
                      echo "<title>The FuMP</title>\r\n";
                      echo "<link>http ://www.thefump.com </link>\r\n";
                      echo "<description>T he Funny Music Project!</description>\r\ n";
                      echo "<lastBuildDate >".$latestBuild Date." 01:00:00 -0500</
                      lastBuildDate>\ r\n";
                      echo "<language> en-us</language>\r\n";
                      echo "<copyright>Cop yright ".date("Y") . " FIDIM Interactive, LLC</
                      copyright>\r\n" ;
                      echo "<generator>dir Castv0.4</generator>\r\n" ;
                      echo "<webMaster>sup port@fidim.com</webMaster>\r\n" ;
                      echo "<ttl>60</ttl>\r\n\r\n";

                      echo "<!--iTunes specific tags-->\r\n";
                      echo "<itunes:catego ry text=\"Comedy\" />\r\n";
                      echo "<itunes:catego ry text=\"Movies &amp; Television\">\r \n"; //
                      NEED TO CONFIRM CATEGORY!
                      echo "<itunes:catego ry text=\"Music\" />\r\n";
                      echo "</itunes:category >\r\n\r\n";

                      echo "<itunes:keywor ds>Sudden Death, Worm Quartet, Luke Ski, Tom
                      Smith, Rob Balder, Raymond and Scum, fump, comedy, Dr. Demento,
                      dementia, funny music, funny songs, funny, weird, music</
                      itunes:keywords >\r\n";
                      echo "<itunes:subtit le>Funny music from some of todays hottest
                      dementia acts!</itunes:subtitle >\r\n";
                      echo "<itunes:summar y>The FuMP is a twice-weekly podcast featuring
                      new, rare, and unreleased songs by some of the biggest names in funny
                      music. These artists are regularly featured on The Dr. Demento Show
                      and routinely perform at science fiction conventions and other places
                      around the country.</itunes:summary> \r\n";
                      echo "<itunes:im age href=\"http://www.thefump.com/logo.jpg\" />\r
                      \n"; // NEED TO CREATE A LOGO GRAPHIC
                      echo "<itunes:author >FIDIM Interactive, LLC</itunes:author>\ r\n";
                      echo "<itunes:owner> \r\n";
                      echo "<itunes:name>T om Rockwell</itunes:name>\r\ n";
                      echo "<itunes:email> support@fidim.c om</itunes:email>\r \n";
                      echo "</itunes:owner>\r \n\r\n";

                      foreach ($allFumps as $fump) {

                      $artist = getData("name", "artists", $fump["artist"]);
                      $timestamp = strtotime($fump["date"]);
                      $buildDate = date("D, d M Y", $timestamp);
                      $link = sprintf("http://www.thefump.com/fumps/%s", $fump["mp3_128"]);
                      $size = filesize("fumps/".$fump["mp3_128"]);
                      if ($fump["explicit"] == "1") {
                      $explicit = "yes";
                      } else {
                      $explicit = "no";
                      }

                      echo "<item>\r\n ";
                      echo "<!--iTunes specific tags-->\r\n";
                      echo "<itunes:author >".$artist." </itunes:author>\ r\n";
                      echo "<itunes:durati on>".$fump["length"]."</itunes:duration >\r\n";
                      echo "<itunes:explic it>".$explicit. "</itunes:explicit >\r\n\r\n"; //
                      NEEDS TO BE YES OR NO

                      echo "<title>".$ fump["title"]."</title>\r\n";
                      echo "<link>".$link. "</link>\r\n";
                      echo "<description>" .$fump["descriptio n"]."</description>\r\ n";
                      echo "<pubDate>".$bu ildDate." 01:00:00 -0500</pubDate>\r\n";
                      echo "<enclosure url=\"".$link." \" length=\"".$siz e."\" type=\"audio/
                      mpeg\"/>\r\n";
                      echo "</item>\r\n";

                      }

                      echo "</channel>\r\n";
                      echo "</rss>\r\n";

                      ?>

                      Comment

                      • Jerry Stuckle

                        #12
                        Re: download counter?

                        devospice wrote:
                        >>It is. The PHP feed works fine. (http://www.thefump.com/cast.php)
                        >>But pointing the link tag to a PHP file instead of an audio file
                        >>generates a "this feed is not valid" error in iTunes.
                        >>->Later.....Spic e
                        >As I said - if the header is correct, it should be OK.
                        >>
                        >I looked at your link, but I didn't see any php files being pointed to -
                        >just the mp3 files themselves.
                        >
                        Sorry. Here's the code for the feed. It pulls the most recent 5
                        entries from the database (ignoring future ones that haven't gone live
                        yet) and formats it. It's based on the code I use to update my Manic
                        Mondays podcast (http://www.suddendeath.org/cast/feed.xml) which I've
                        never had a problem with. But those always point directly to the MP3
                        file.
                        >
                        ->Later.....Spic e
                        >
                        <?php
                        >
                        // NOTE: All links point to the site folder, which must be changed
                        upon launch.
                        >
                        include("functi ons.php");
                        >
                        // Get the 5 most recent fumps.
                        $today = date("Y-m-d");
                        $fumpSQL = "SELECT * FROM fumps WHERE date<=CURDATE() ORDER BY date
                        DESC LIMIT 5";
                        $allFumps = getDataFromTabl e($fumpSQL);
                        >
                        // Calculate the last build date.
                        $lastFump = $allFumps[0];
                        $lastDate = $lastFump["date"]; // YYYY-MM-DD
                        $timestamp = strtotime($last Date);
                        $latestBuildDat e = date("D, d M Y", $timestamp);
                        >
                        echo "<?xml version=\"1.0\" ?>\r\n";
                        echo "<rss xmlns:itunes=\" http://www.itunes.com/DTDs/Podcast-1.0.dtd\"
                        version=\"2.0\" >\r\n";
                        echo "<channel>\r\n" ;
                        echo "<title>The FuMP</title>\r\n";
                        echo "<link>http ://www.thefump.com </link>\r\n";
                        echo "<description>T he Funny Music Project!</description>\r\ n";
                        echo "<lastBuildDate >".$latestBuild Date." 01:00:00 -0500</
                        lastBuildDate>\ r\n";
                        echo "<language> en-us</language>\r\n";
                        echo "<copyright>Cop yright ".date("Y") . " FIDIM Interactive, LLC</
                        copyright>\r\n" ;
                        echo "<generator>dir Castv0.4</generator>\r\n" ;
                        echo "<webMaster>sup port@fidim.com</webMaster>\r\n" ;
                        echo "<ttl>60</ttl>\r\n\r\n";
                        >
                        echo "<!--iTunes specific tags-->\r\n";
                        echo "<itunes:catego ry text=\"Comedy\" />\r\n";
                        echo "<itunes:catego ry text=\"Movies &amp; Television\">\r \n"; //
                        NEED TO CONFIRM CATEGORY!
                        echo "<itunes:catego ry text=\"Music\" />\r\n";
                        echo "</itunes:category >\r\n\r\n";
                        >
                        echo "<itunes:keywor ds>Sudden Death, Worm Quartet, Luke Ski, Tom
                        Smith, Rob Balder, Raymond and Scum, fump, comedy, Dr. Demento,
                        dementia, funny music, funny songs, funny, weird, music</
                        itunes:keywords >\r\n";
                        echo "<itunes:subtit le>Funny music from some of todays hottest
                        dementia acts!</itunes:subtitle >\r\n";
                        echo "<itunes:summar y>The FuMP is a twice-weekly podcast featuring
                        new, rare, and unreleased songs by some of the biggest names in funny
                        music. These artists are regularly featured on The Dr. Demento Show
                        and routinely perform at science fiction conventions and other places
                        around the country.</itunes:summary> \r\n";
                        echo "<itunes:im age href=\"http://www.thefump.com/logo.jpg\" />\r
                        \n"; // NEED TO CREATE A LOGO GRAPHIC
                        echo "<itunes:author >FIDIM Interactive, LLC</itunes:author>\ r\n";
                        echo "<itunes:owner> \r\n";
                        echo "<itunes:name>T om Rockwell</itunes:name>\r\ n";
                        echo "<itunes:email> support@fidim.c om</itunes:email>\r \n";
                        echo "</itunes:owner>\r \n\r\n";
                        >
                        foreach ($allFumps as $fump) {
                        >
                        $artist = getData("name", "artists", $fump["artist"]);
                        $timestamp = strtotime($fump["date"]);
                        $buildDate = date("D, d M Y", $timestamp);
                        $link = sprintf("http://www.thefump.com/fumps/%s", $fump["mp3_128"]);
                        $size = filesize("fumps/".$fump["mp3_128"]);
                        if ($fump["explicit"] == "1") {
                        $explicit = "yes";
                        } else {
                        $explicit = "no";
                        }
                        >
                        echo "<item>\r\n ";
                        echo "<!--iTunes specific tags-->\r\n";
                        echo "<itunes:author >".$artist." </itunes:author>\ r\n";
                        echo "<itunes:durati on>".$fump["length"]."</itunes:duration >\r\n";
                        echo "<itunes:explic it>".$explicit. "</itunes:explicit >\r\n\r\n"; //
                        NEEDS TO BE YES OR NO
                        >
                        echo "<title>".$ fump["title"]."</title>\r\n";
                        echo "<link>".$link. "</link>\r\n";
                        echo "<description>" .$fump["descriptio n"]."</description>\r\ n";
                        echo "<pubDate>".$bu ildDate." 01:00:00 -0500</pubDate>\r\n";
                        echo "<enclosure url=\"".$link." \" length=\"".$siz e."\" type=\"audio/
                        mpeg\"/>\r\n";
                        echo "</item>\r\n";
                        >
                        }
                        >
                        echo "</channel>\r\n";
                        echo "</rss>\r\n";
                        >
                        ?>
                        >
                        OK, I'm not that familiar with the iTunes RSS feeds, but it looks OK.

                        It looks like iTunes does check the file extension, which is pretty
                        stupid. But maybe they do.

                        In this case, you would probably have to use Apache's mod_rewrite to
                        redirect the download. In your link tag put something like
                        "/tunes/mytune.mpg". Then have a redirect in your httpd.conf or
                        ..htaccess file to redirect anything from the /tunes directory to your
                        script, passing the filename as a parameter. This might get you around
                        the restriction - I don't know what else iTunes might be looking for.

                        You can get more info on how to use mod_rewrite in alt.apache.conf iguration.

                        The only other think I could suggest would be that you ask the itunes
                        support people about it. They might have some answers. Or there might
                        be another tag you'd could fill in to handle it.


                        --
                        =============== ===
                        Remove the "x" from my email address
                        Jerry Stuckle
                        JDS Computer Training Corp.
                        jstucklex@attgl obal.net
                        =============== ===

                        Comment

                        • devospice

                          #13
                          Re: download counter?

                          In this case, you would probably have to use Apache's mod_rewrite to
                          redirect the download.
                          Interesting. I didn't know that could be done. I'll look into it.
                          Thanks.
                          The only other think I could suggest would be that you ask the itunes
                          support people about it. They might have some answers.
                          Yeah, I'm planning on doing that too. I just have lots of other
                          things to do first. :)

                          ->Later.....Spic e

                          Comment

                          Working...