# Hit counter for streamed sound

**URL:** https://forum.kirupa.com/t/hit-counter-for-streamed-sound/38856
**Category:** Uncategorized
**Created:** [December 30, 2003, 8:13pm UTC](https://forum.kirupa.com/t/hit-counter-for-streamed-sound/38856 "2003-12-30T20:13:34Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![aconeinc](https://avatars.discourse-cdn.com/v4/letter/a/e274bd/32.png) [@aconeinc](https://forum.kirupa.com/u/aconeinc)
#### Post date: [December 30, 2003, 8:13pm UTC](https://forum.kirupa.com/t/hit-counter-for-streamed-sound/38856/1 "2003-12-30T20:13:34Z")

</div>

How can I make a visible hit counter for sound streams, not page hits? My sounds buttons currently use the mysound/loadsound action to stream external mp3. How can I make a visible counter to keep a tab of how many times music is streamed?

thanks in advance for your reply  
ken

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [December 30, 2003, 9:03pm UTC](https://forum.kirupa.com/t/hit-counter-for-streamed-sound/38856/2 "2003-12-30T21:03:37Z")

</div>

With what? asp? php? perl? …etc?

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [December 30, 2003, 10:21pm UTC](https://forum.kirupa.com/t/hit-counter-for-streamed-sound/38856/3 "2003-12-30T22:21:42Z")

</div>

php is the only one i’m familiar with so I guess that

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [December 31, 2003, 6:32am UTC](https://forum.kirupa.com/t/hit-counter-for-streamed-sound/38856/4 "2003-12-31T06:32:11Z")

</div>

ok…It’s just like every other counter: flash calls a php file which will open a txt file, increase the number in it and write it to the same file and if needed returns the number. The only difference is that the php needs to be called when the sound starts playing.

```php

$count = file_get_contents("count.txt");
$count++;
$fp = fopen("count.txt", "w+");
fwrite($fp, $count);
fclose($fp);

```

Now you should make a text file named “count.txt” and type a number ‘0’ in it (I’m not sure if this is necessary but just in case) and change it’s permissions to 777 when you upload the file to your server.  
Now in flash you need to trigger the php file once the sound starts loading.  
So for the buttons that should load a sound add this action:

```auto

loadVariablesNum("counter.php", 0);

```

Just make sure that the file in the quotes is the php file…

PS! There should be a hit counter tute coming soon.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [December 31, 2003, 6:09pm UTC](https://forum.kirupa.com/t/hit-counter-for-streamed-sound/38856/5 "2003-12-31T18:09:50Z")

</div>

I did everything you specified first to test it. I added the load variable code to my flash button, made a counter.php file and a count.txt file (with 0). But when I test it by uploading everything, opening a new browser and pressing play, I check back with my web admin and in the count.txt file, the value is still 0. I changed the permissiom too. What might be doing wrong?

In addition, I wanted that number to be visible on the page where users press play

take a look at this page and see where it says total plays, I am trying to make a visible counter right under it.

[www.aconeinc.com/beats.htm](http://www.aconeinc.com/beats.htm)

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [December 31, 2003, 10:13pm UTC](https://forum.kirupa.com/t/hit-counter-for-streamed-sound/38856/6 "2003-12-31T22:13:42Z")

</div>

k… run the php file in your browser (on the server, not locally) and see if it gives you any error messages…

to see the count number in flash add this line at the end of your php file:

print “&count=”.$count;

the variable name of your dynamic textbox here should be “count” (you can change it to whatever but make sure you change te php file too)

and now to make sure flash displays the count correctly make sure the paths are correct (loadVariablesNum action is in the same movieclip where your dynamic textfile is).
