Can someone give me some direction on how to make a simple hits counter in php? I want Flash to be able to call this php script, which will then increase a counter by 1. Thats all I need. Don't need the php to return anything to Flash either.

I think I might have to open a file, read a variable from that file, increase it by 1 and then write the file back out? But I don't know how to do that! 🙁

Thanks for any help.

    Thanks, I managed to get a simple php counter work, but I'm finding that it's not recording all of the hits. For example, if I do 3 clicks on my banner, first click...wait for the link to load.....click again, wait for the link to load and then a 3rd click and wait for the link to load.......when I check my .txt file only the first click is showing as have happened.

    What I'm bothered about is that if I get lots of people clicking on different banners, will only 1 of them register? or was the problem just due to the banner I was clicking on, because the first click hadn't done it's thing yet?

      you could try somthing like this

      $num = file("cnt.txt");
      ++$num[0];
      $file = fopen("cnt.txt", "w");
      fwrite($file, $num[0]);
      fclose($file);
      
        phaseonemedia wrote:

        ALL HAIL GOOGLE!!!

        Change that to Dougal and I agree! 😉

        What I'm bothered about is that if I get lots of people clicking on different banners, will only 1 of them register? or was the problem just due to the banner I was clicking on, because the first click hadn't done it's thing yet?

        Shows us the code you are using and we'll try and see whats wrong with it. There is no reason why only one of them would register. If you have a VERY busy website then its possible PHP could end up trying to write to the file twice and then some of the updates might fail.

        However, if its getting that busy I'd suggest you'd want more sophisticated stats anyway.

          <?php 
           $hits = file_get_contents("hits.txt"); 
           $hits = $hits + 1; 
          
           $handle = fopen("hits.txt", "w"); 
           fwrite($handle, $hits); 
           fclose($handle); 
          ?>

          I'm using the above.

          Another issue is I would want to try to do the same for a button on a page in wordpress. Any ideas how I would do that?

            Write a Reply...