• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Counting clicks

DFX

OSNN Senior Addict
#1
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?
 

SPeedY_B

I may actually be insane.
#4
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..
 

SPeedY_B

I may actually be insane.
#5
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

Latest posts

Latest profile posts

Perris Calderon wrote on Electronic Punk's profile.
Ep, glad to see you come back and tidy up...did want to ask a one day favor, I want to enhance my resume , was hoping you could make me administrator for a day, if so, take me right off since I won't be here to do anything, and don't know the slightest about the board, but it would be nice putting "served administrator osnn", if can do, THANKS

Been running around Quora lately, luv it there https://tinyurl.com/ycpxl
Electronic Punk wrote on Perris Calderon's profile.
All good still mate?
Hello, is there anybody in there? Just nod if you can hear me ...
Xie
What a long strange trip it's been. =)

Forum statistics

Threads
61,962
Messages
673,240
Members
89,015
Latest member
loxioalix