Counting clicks

DFX

OSNN Senior Addict
Joined
17 Aug 2002
Messages
342
Hi,

Im making a website so I can host my own DJ mixes. I was wondering if there was a counter that counts how many clicks so I can display it on the page.

So it looks like this:

March Mix
Listen [amount of users listened: 28]

Anyone got any ideas?
 
MySQL isn't an option Im afraid. Is there anyway I can use a .txt file or something similar?
 
Your page
<a href="dlmix.php?download=mix.mp3">mix.mp3</a> downloaded <?include("mix.txt");?> times

dlmix.php
<?php
if (file_exists("mix.txt")) {
$file = fopen("mix.txt", "r+");
flock($file, 1);
$count = fgets($file, 4096);
$count += 1;
fseek($file,0);
fputs($file,$count);
flock($file, 3);
fclose($file);
}
header("location: $download");
?>


I think that will work, I haven't tried it tho..
 
Ok, changed it about a bit, added a function to make it easier

The Page
Code:
<?php 
function download($download) { print "
<a href=\"download.php?download=$download\">Listen</a><br><b> ";
include("$download.txt");
print "</b> people listened so far";
}
?>
//content
March Mix - <? download("audio/march.mp3"); ?>
<br>
April Mix - <? download("audio/april.mp3"); ?>

//content

download.php
Code:
<?php
if (file_exists("$download.txt")) {
$file = fopen("$download.txt", "r+");
flock($file, 1);
$count = fgets($file, 4096);
$count += 1;
fseek($file,0);
fputs($file,$count);
flock($file, 3);
fclose($file);
}
else print "Invalid download specified";
break;
header("location: $download");
?>

Now all you need is to aim the download(); function at a file, and have another file in the same directory with the same name and the addition of a .txt extension :)
example :
download.php?download=audio/blah.mp3
you will require audio/blah.mp3.txt to exist.
 

Members online

No members online now.

Latest profile posts

Also Hi EP and people. I found this place again while looking through a oooollllllldddd backup. I have filled over 10TB and was looking at my collection of antiques. Any bids on the 500Mhz Win 95 fix?
Any of the SP crew still out there?
Xie wrote on Electronic Punk's profile.
Impressed you have kept this alive this long EP! So many sites have come and gone. :(

Just did some crude math and I apparently joined almost 18yrs ago, how is that possible???
hello peeps... is been some time since i last came here.
Electronic Punk wrote on Sazar's profile.
Rest in peace my friend, been trying to find you and finally did in the worst way imaginable.

Forum statistics

Threads
62,015
Messages
673,494
Members
5,621
Latest member
naeemsafi
Back