Click to See Complete Forum and Search --> : how 2 create statistics, flash/php
pokko
05-16-2002, 07:43 AM
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!
nucleuz
05-16-2002, 08:37 AM
you need two files:
1. counter.txt -> put a 0 in it
2. counter.php :
<?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.
pokko
05-16-2002, 08:57 AM
mmm doesent seem to work:
I call it in flash using:
on (release) {
loadVariablesNum("counter.php", 0, "POST");
}
is this correct?
nucleuz
05-16-2002, 09:44 AM
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.
pokko
05-16-2002, 10:01 AM
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!
le_saut
05-16-2002, 10:01 AM
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
nucleuz
05-16-2002, 10:16 AM
But then again a .php file with just the 0 in will show up as well......
Anyway; glad you got it going.
le_saut
05-16-2002, 10:41 AM
correct, hmmmm.
I guess it's just a number and can't be related to anything.
nucleuz
05-16-2002, 10:51 AM
But if you are paranoid ,in this case it is a number: who would?? But later on it could be something else:
<?php
$file = "/dir/not/available/via/www/easy_counter.txt";
?>
flashkit.com
Copyright WebMediaBrands Inc., All Rights Reserved.