-
I want to keep score of how many times a button gets pressed in my site. I think it should be possible to send data to php file whenever its pressed. PHP should add 1 (hit) for that button. Trouble is I'm no hero in scripting.
Anybody out there who can help me out with this?
The purpose is to create somekind of statistics on how many times the button is pressed.
Tnx!
-
you need two files:
1. counter.txt -> put a 0 in it
2. counter.php :
Code:
<?php
$file = "counter.txt";
$fp = fopen($file, "r");
$cnt = fread($fp, 1024);
$cnt++;
fclose($fp);
$fp = fopen($file, "w");
fputs($fp, $cnt);
fclose($fp);
?>
Now: call this each time you click your button and you should see the number increase.
-
mmm doesent seem to work:
I call it in flash using:
Code:
on (release) {
loadVariablesNum("counter.php", 0, "POST");
}
is this correct?
-
Well, it works for me, do you have the counter.txt with a 0 in it???
Does http://localhost/counter.php give you any warnings?? You might have to chmod the counter.txt file to get it running.
-
it works! thumbs up ;)
ideed had to chmod the txtfile, chmodded the dir, thuoght that was enough. But it works great now!
Thanks a lot!
-
CHMOD 755 counter.txt
Remember your server could get mighty slow if users are continually sending info to a file.
Also contents of txt files are able to be viewed in a browser much better to give the file a .php extension.
James
-
But then again a .php file with just the 0 in will show up as well......
Anyway; glad you got it going.
-
correct, hmmmm.
I guess it's just a number and can't be related to anything.
-
But if you are paranoid ,in this case it is a number: who would?? But later on it could be something else:
Code:
<?php
$file = "/dir/not/available/via/www/easy_counter.txt";
?>