By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,241 Members | 760 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,241 IT Pros & Developers. It's quick & easy.

download counter?

P: n/a
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
Share this Question
Share on Google+
12 Replies


P: n/a
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

P: n/a
"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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.