472,993 Members | 2,220 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,993 software developers and data experts.

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.....Spice

Feb 7 '07 #1
12 2842
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...@suddendeath.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.....Spice

Feb 8 '07 #2
"lorento" <la**********@yahoo.compíse v diskusním príspevku
news:11*********************@j27g2000cwj.googlegro ups.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.)

Feb 8 '07 #3
On Feb 7, 11:03 pm, "lorento" <laurente1...@yahoo.comwrote:
I think you can make simple php application for count the download,
like:
when people clickhttp://host/download.php?file=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

Feb 9 '07 #4
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

Feb 9 '07 #5
Rik
On Fri, 09 Feb 2007 16:33:48 +0100, devospice <sp***@suddendeath.org
wrote:
On Feb 7, 11:03 pm, "lorento" <laurente1...@yahoo.comwrote:
>I think you can make simple php application for count the download,
like:
when people clickhttp://host/download.php?file=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
Feb 9 '07 #6
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.
js*******@attglobal.net
==================
Feb 9 '07 #7
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.....Spice

Feb 13 '07 #8
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.....Spice

Feb 13 '07 #9
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.....Spice
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.
js*******@attglobal.net
==================
Feb 14 '07 #10
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.....Spice

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.....Spice

<?php

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

include("functions.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 = getDataFromTable($fumpSQL);

// Calculate the last build date.
$lastFump = $allFumps[0];
$lastDate = $lastFump["date"]; // YYYY-MM-DD
$timestamp = strtotime($lastDate);
$latestBuildDate = 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>The Funny Music Project!</description>\r\n";
echo "<lastBuildDate>".$latestBuildDate." 01:00:00 -0500</
lastBuildDate>\r\n";
echo "<language>en-us</language>\r\n";
echo "<copyright>Copyright ".date("Y"). " FIDIM Interactive, LLC</
copyright>\r\n";
echo "<generator>dirCastv0.4</generator>\r\n";
echo "<webMaster>su*****@fidim.com</webMaster>\r\n";
echo "<ttl>60</ttl>\r\n\r\n";

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

echo "<itunes:keywords>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:subtitle>Funny music from some of todays hottest
dementia acts!</itunes:subtitle>\r\n";
echo "<itunes:summary>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:image 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>Tom Rockwell</itunes:name>\r\n";
echo "<itunes:email>su*****@fidim.com</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:duration>".$fump["length"]."</itunes:duration>\r\n";
echo "<itunes:explicit>".$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["description"]."</description>\r\n";
echo "<pubDate>".$buildDate." 01:00:00 -0500</pubDate>\r\n";
echo "<enclosure url=\"".$link."\" length=\"".$size."\" type=\"audio/
mpeg\"/>\r\n";
echo "</item>\r\n";

}

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

?>

Feb 19 '07 #11
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.....Spice
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.....Spice

<?php

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

include("functions.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 = getDataFromTable($fumpSQL);

// Calculate the last build date.
$lastFump = $allFumps[0];
$lastDate = $lastFump["date"]; // YYYY-MM-DD
$timestamp = strtotime($lastDate);
$latestBuildDate = 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>The Funny Music Project!</description>\r\n";
echo "<lastBuildDate>".$latestBuildDate." 01:00:00 -0500</
lastBuildDate>\r\n";
echo "<language>en-us</language>\r\n";
echo "<copyright>Copyright ".date("Y"). " FIDIM Interactive, LLC</
copyright>\r\n";
echo "<generator>dirCastv0.4</generator>\r\n";
echo "<webMaster>su*****@fidim.com</webMaster>\r\n";
echo "<ttl>60</ttl>\r\n\r\n";

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

echo "<itunes:keywords>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:subtitle>Funny music from some of todays hottest
dementia acts!</itunes:subtitle>\r\n";
echo "<itunes:summary>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:image 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>Tom Rockwell</itunes:name>\r\n";
echo "<itunes:email>su*****@fidim.com</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:duration>".$fump["length"]."</itunes:duration>\r\n";
echo "<itunes:explicit>".$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["description"]."</description>\r\n";
echo "<pubDate>".$buildDate." 01:00:00 -0500</pubDate>\r\n";
echo "<enclosure url=\"".$link."\" length=\"".$size."\" 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.configuration.

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.
js*******@attglobal.net
==================
Feb 20 '07 #12
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.....Spice

Feb 21 '07 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Jim Willsher | last post by:
Hi all, PHP 4.2.2 on RedHat9 I have some files on my website for people to download, and I want to generate the file location "on the fly", so the URL is held in a database. I have a simple...
4
by: Bernhard | last post by:
I am not sure if php can achieve this, but i guess that my problem shoulb be solved with an server side language. Is there any way i can tell if a visitor of my website has finished a download?...
3
by: Michael | last post by:
I am trying to allow a user to view a PDF in a new window. I currently have this working using the following: <a href="./pdf.do?parameter=01121980" target="top"><b>pdf</b></a> The problem...
8
by: William Starr Moake | last post by:
I'm trying to script a download counter that will display the total number on the download page without server-side scripting. Below is my very incomplete beginning. It returns no errors, but...
0
by: Marius III | last post by:
Hi there, I am building a File download counter in PHP5. It's working fine but the problem is that its not working with any Download Managers for ex: Free Download Manager / DAP etc. The...
5
by: Mickey | last post by:
Hi all, Is there a way to find out when a user has completed a download? I ask this because I have a current system where users download files, however due to serious bandwidth issues I need...
7
by: mistral | last post by:
I use htaccess to protect directory and granting access to download file only for the authorized users. Just want implement simple PHP file download counter for single file. I need track the number...
3
by: malaysiauser | last post by:
Dear all, Last year I install a download control script in Linux server. its working. This year i'd changed my hosting server to other company. i'd tried install the script. It was installed...
1
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
3
SueHopson
by: SueHopson | last post by:
Hi All, I'm trying to create a single code (run off a button that calls the Private Sub) for our parts list report that will allow the user to filter by either/both PartVendor and PartType. On...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.