Download counter

  • Frax
  • Novice
  • Novice
  • Frax
  • Posts: 18
  • Loc: San Jose, Costa Rica

Post 3+ Months Ago

Hi, i would like to know if there's any download counter that can count each file download without having a data base installed on the network?? Something like a txt file with a +1 +1 +1 +1 counter.
thnks.
  • UNFLUX
  • Genius
  • Genius
  • User avatar
  • Posts: 6375
  • Loc: twitter.com/unflux

Post 3+ Months Ago

i'm pretty sure it can be done with a perl script. am I right bigweb?

[he's the perl-guy ;)]
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9099
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

Yeah you could easily write your own program in PERL to do that. You would just have to use a flat file database. You wouldn't need anything like MySQL. Basically it just keeps track of the count in a file that right on your server.
  • Borrow -A- Geek
  • Professor
  • Professor
  • User avatar
  • Posts: 763
  • Loc: Dallas/Ft Worth, Texas

Post 3+ Months Ago

found the world simplist perl counter script, i could written this one myself in about 10 minutes.. i would have probably spent another 10 minutes to count only unique ip's though..



Code: [ Select ]
#!/usr/bin/perl -w

use strict;
use CGI qw/:all/;

# This is the path to the file that will contain the
# counter hits, chmod this file to 666
my $countdat = "/usr/share/apache/www/counter/count.dat";

# An alternative to using CGI header is to specify the
# content type manually by uncommenting the next line
# print "Content-type:text/html\n\n";
print header;

# If the count.dat file exists, is readable and writable
# open it and store the number in a variable called $count
if ( (-e "$countdat") && (-r "$countdat")
   && (-w "$countdat") )
{
 open(DAT, "$countdat") || die "Problem: $!";
 my $count = <DAT>;
 close(DAT);

 # Add 1 to this number (increment the number of hits)
 $count++;

 # Update the count.dat file with the new value
 open(COUNT, ">$countdat") || die "Problem: $!";
 print COUNT $count;
 close(COUNT);
 print "$count";
} else {
 print "the counter file is not readable or writable\n";
}
  1. #!/usr/bin/perl -w
  2. use strict;
  3. use CGI qw/:all/;
  4. # This is the path to the file that will contain the
  5. # counter hits, chmod this file to 666
  6. my $countdat = "/usr/share/apache/www/counter/count.dat";
  7. # An alternative to using CGI header is to specify the
  8. # content type manually by uncommenting the next line
  9. # print "Content-type:text/html\n\n";
  10. print header;
  11. # If the count.dat file exists, is readable and writable
  12. # open it and store the number in a variable called $count
  13. if ( (-e "$countdat") && (-r "$countdat")
  14.    && (-w "$countdat") )
  15. {
  16.  open(DAT, "$countdat") || die "Problem: $!";
  17.  my $count = <DAT>;
  18.  close(DAT);
  19.  # Add 1 to this number (increment the number of hits)
  20.  $count++;
  21.  # Update the count.dat file with the new value
  22.  open(COUNT, ">$countdat") || die "Problem: $!";
  23.  print COUNT $count;
  24.  close(COUNT);
  25.  print "$count";
  26. } else {
  27.  print "the counter file is not readable or writable\n";
  28. }


Script explanation - SSI:
Files that contain SSI code to be executed normally have an extension such as '.shtml' - This can be changed, but is out of the context of this article.

In order for you to run SSI, you will need to rename your '.html' file to '.shtml'. The line that you need to add to your file from which the counter will be used is:
<!--#exec cgi="/path/to/cgi/counter.pl"-->
Now, everytime your page is loaded, the counter is incremented and the current value is displayed instead of the line between the <!-- and the -->.
  • UNFLUX
  • Genius
  • Genius
  • User avatar
  • Posts: 6375
  • Loc: twitter.com/unflux

Post 3+ Months Ago

sounds perfect! I hope Frax comes back around to see it. :?

Post Information

  • Total Posts in this topic: 5 posts
  • Users browsing this forum: No registered users and 23 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.