I want a counter to track number of clicks on various song links on my html page and that number to be visible at a location on that page.

I made a counter.php script:

<?php
$count = file_get_contents("count.txt");
$count = explode("=", $count);
$count[1] = $count[1]+1;
$file = fopen("count.txt", "w+");
fwrite($file, "count=".$count[1]);
fclose($file);
print "count=".$count[1];
?>

I also have a count.txt file with a value of 0. So far I have the essential tools. My delima is:

  1. How to make the links trigger a count each time they are clicked in addition to playing the song that was click on. Instead of
    <a href="http://www.aconeinc.com/sounds/hollademo.m3u">Hi-fi for instance, what should it be?

  2. How to make that value in the count.txt to be visible on my html page. How do I insert it on a given location on my page?

Thank you
Ken

    Ok firstly the page must be PHP, it can be another language like Perl, ASP but thats beside the point its a PHP Forum 😃

    Anyway as soon as the pages accessed you will need the Counter Code at Top. Or at least before you re-access the file to display the correct number of hits to that page.

    Also if you are wanting to show unique hits by this i mean hits for each page you will need to organise your text file correctly so e.g.

    index|1
    news|10

    From there you need to use file(); which you have it basically just opens the entire file for reading.

    from there you need to explode it to

    so

    explode("|",$contents);

    to get the index and 1 as seperate values.

    From there you will need to just echo out the hit value in my example it will be one.

      My page is in html and I made it in dreamweaver. The counter script I have works fine cause I was using it for a flash page initially(www.aconeinc.com/beats.htm) . But now I want it for my html page. All I need is an html code to insert it in my page and a different code for the lin so that a count is triggered. Thanks

        easiest way to organize information is the associative array with URL as key and hit count as value. Load it, increment count and serialize back to file.

        like this pseudocode:

        $counters=unserialize(loadFile($filename));
        echo ++$counters[$_SERVER["REQUEST_URI"]];
        saveFile($filename,serialize($counters));

        to count media file you can:

        1. give media files using redirect php page - dirty and unreliable
        2. give media files using php page ( header() + readfile() ) - better way.
        3. best way - analyze Apache log and move information to database. But don't do it now: first you need more experience.
          Write a Reply...