PDA

View Full Version : Php Counter....help!!!


Mr Allworthy
11-02-2003, 11:24 AM
PLEASE HELP ME WITH MY COUNTER!!!
I'm trying to make a hit counter with flash MX and PHP, but it wont work. I have done sevral tutorials, and tried to pick up information from forums, but nothing seems to work.

I would really appreciate if someone of you script guys could help me out....I've tried everything....

I've used Flash MX and PHP to make mailforms etc without having any problems, but this makes me...... ¤£##´€$£

Heres what I've done so far:

The Flash movie has uses only one frame on the main timeline which contains a movieclip(loads in the numbers of visitors) which is based on three frames with the following scripts:

Frame one:

if (startup eq "") {
startup = "Run Already";
loadVariables("counter.txt?" add random(2000), "/counter");
}

Frame two:

if (loaded == "1") {
gotoAndPlay(3);
} else {
gotoAndPlay(1);
}

Frame three:

count = Number(count) + 1;
loadVariablesNum ("counter.php?count=" + count, 0);
stop ();

While the PHP script:
<html>
<head>
<title>Counter Module For Tutorial</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#FFFFFF">
<?php $fd = fopen("counter.txt", "w");
fwrite($fd, "count=".$_GET['count']."&loaded=1");
fclose($fd); ?>
<p>Counter incrimented: value is now <?php echo $_GET['count'];
</body>
</html>
And finally th Notepad text file wich contains the number of visitors:

count=0&loaded=1

Hope someone can find out whats wrong, because I can't...

CyanBlue
11-02-2003, 11:57 AM
Howdy and Welcome... ;)

Where is your counter??? :confused:
Show us your code and maybe somebody can help you fix the problem...
You will probably get redirected to another tutorial or whatever without your script...

Just my 2 cents... ;)

Motion2082
11-04-2003, 01:39 PM
I was having the same problem as you last week.....see this thread < http://www.actionscript.org/forums/showthread.php3?s=&threadid=36885 >

If you are in a hurry, this is what you need


counter = new LoadVars();
counter.onLoad = function(ok) {
if (ok) {
counter_txt.text = this.result;

} else {
counter_txt.text = "???";
}
};
counter.load("count.php");



<?php
$COUNT_FILE = "count_data.txt";

if (file_exists($COUNT_FILE)) {
$fp = fopen("$COUNT_FILE", "r+");
flock($fp, 1);
$count = fgets($fp, 4096);
$count += 1;
fseek($fp,0);
fputs($fp, $count);
flock($fp, 3);
fclose($fp);
$message="$count";
echo "result=$message";
} else {
$message="???";
echo "result=$message";
}
?>


& then call your text file "COUNT_DATA.txt" & type the numeric value 0 & save the TXT file //this sets the counter to zero

Upload your TXT, SWF, PHP file to the HTML folder on your server, make sure you make the TXT file writable & you should be ok ;)

GOOD LUCK :p

Motion2082
11-04-2003, 01:46 PM
between you and me, Jesse needs to update his PHP Counter in the Tutorials section. Its outdated & causes problems for everyone who tries to understand it.

It was good at the time but needs updating ;)

Mr Allworthy
11-04-2003, 03:38 PM
Thank you for all your help, but I'm sorry to say that I still can't get it to work....I just can't understand why or what's wrong? I have downloaded every attachment found in the answers you received, but those don't work either?

Has it anything to do with how I publish the Flash file? I work in Flash MX and I publish the movie in Flash 6. Could that infect it?

I probably seem very thick headed...and yes, when it comes to PHP and server side scripting, well......? This is starting to be embarrassing, but I won’t give up just yet...:confused:

If you... Motion2082...(who's been very helpful) or anyone else out there, who's got an answer for me...PLEASE help me find this thing out...

If not...I'm really thankful for you help so far Motion2082 :)

freddycodes
11-04-2003, 07:28 PM
If you are using

<html>
<head>
<title>Counter Module For Tutorial</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#FFFFFF">
<?php $fd = fopen("counter.txt", "w");
fwrite($fd, "count=".$_GET['count']."&loaded=1");
fclose($fd); ?>
<p>Counter incrimented: value is now <?php echo $_GET['count'];
</body>
</html>


Its definitely not working as Flash doesn't know how to handle all the html wrapped around your php code.

Try something like what was posted above.

<?php
$fd = fopen("counter.txt", "w");
fwrite($fd, "&count=".$_GET['count']."&loaded=1");
fclose($fd);
?>

Motion2082
11-05-2003, 12:25 AM
Make sure you have only one copy of all three files on your server. If your SWF is a loadMovie you can duplicate it and put it in your CGI-BIN.

How did you upload your files? Make sure your attributes are correct...ie file permissions are 666 or more

astroscout7
10-05-2004, 06:35 PM
Mr. Allworthy.... Have you [or anyone else really] actually gotten a counter to work? I have read EVERY tutorial and read every forum post and I STILL can't get any of the counters to work!

Thanks!

CyanBlue
10-05-2004, 07:50 PM
What about posting your code so that somebody can take a look??? :)

astroscout7
10-05-2004, 10:11 PM
All of the code I have and have tried to "tweak" has been downloaded from either Jesse's tutorial or from another actionscripts.org users post ... I have attached what I've done (with very minor tweaks.... no code has been changed from Jesse's tute!)

Thanks for the help!

CyanBlue
10-05-2004, 11:11 PM
Well... I don't know if I understand what's in that file or not, but you can take a look at this one...

My sample is here...
http://cyanblue.flashvacuum.com/tmp/Counter/Counter.html

The file can be found in this thread...
http://www.actionscript.org/forums/showthread.php3?t=40491

If you have problem on your machine or your host, that probably is the problem of the file permission...