;

PDA

Click to See Complete Forum and Search --> : CODE : Hit Counter


dniezby
04-19-2003, 03:17 AM
Since it took me FOREVER to figure this out, I figure I'd share the knowledge. Below is the method I've come up with for creating a 3dfa hit counter. NOTE: This method will count all hits...So when someone reloads the page, it will add another hit.
----------------------------------------------
First, create a page to hold the current count.
TOTAL_COUNT.TXT

In the file you can put any value you'd like for your starting number. I started with 1000.

You MUST CHMOD this file to 666 or it will not be able to be written to.

----------------------------------------------
Now you need to create the script to process the counts.
call it counter.php

<?
$counterval = 0;
$fp = fopen( "./total_count.txt","r"); //Change txt file's location
$counterval = fread($fp, 26 );
fclose( $fp );
$counterval = (integer)$counterval + 1;
$fp = fopen( "./total_count.txt","w+"); //Change txt file's location
fwrite( $fp, $counterval, 26);
fclose( $fp );
echo "&newcount=$counterval"; //newcount is the name of the editbox
//in 3dfa.
?>


----------------------------------------------
Now for the 3dfa file.

This is the easiest part.

Create a small movie.
Add an editbox and assign variable "newcount"
format the text, it's color and it's look.

Select "Starting Script" and put this
loadVariables ("url to counter.php","GET");

That's it!
---------------------------------------------
I hope that this will help people.
NOTE: If you don't name your edit box "newtotal" then make sure to change the echo command to: echo "&3dfa_variablename=$counterval";

dniezby
04-19-2003, 10:33 PM
Here are the source files for the above hit counter.
I would recommend that you put the flash file in a frame that loads when a new visitor arrives. If you put it on a page, then someone can just keep refreashing to add visitors.

HERE IS AN EXAMPLE (http://www.pmedic.com/usmr)

gkircheis
09-28-2003, 10:10 PM
thank you so much for posting that. I have been trying but I couldn't get that to work. Can you explain some more how the ascript part? What's "url to counter.php"?
Cheers, mate

blanius
09-29-2003, 06:43 AM
That aint ASP, it's PHP ASP would be so much harder to read :)

url to counter would be something like

http://bretlanius.com/counter.php

but using your information.

And I hope the originator of the thread doesn't mind but I commented the PHP portion for you.


<?
$counterval = 0;//Sets the initial value to 0
$fp = fopen( "./total_count.txt","r"); //Change txt file's location
$counterval = fread($fp, 26 );//read the value from the file
fclose( $fp );//close the open file
$counterval = (integer)$counterval + 1;//increment the value
$fp = fopen( "./total_count.txt","w+"); //Change txt file's location
fwrite( $fp, $counterval, 26);//Save the new value in the file
fclose( $fp );//close the newly opened file
//send the response back to 3dfa as a variable to display
echo "&newcount=$counterval"; //newcount is the name of the editbox
//in 3dfa.
?>

gkircheis
09-29-2003, 12:01 PM
Thanks a bunch for the comment lines. I think I understand what's going on now. :p
Cheers