A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: CODE : Hit Counter

  1. #1
    Senior Member
    Join Date
    Jul 2001
    Location
    Tinley Park, IL
    Posts
    702

    CODE : Hit Counter

    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
    PHP Code:
    <?
    $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";

  2. #2
    Senior Member
    Join Date
    Jul 2001
    Location
    Tinley Park, IL
    Posts
    702
    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

  3. #3
    Junior Member
    Join Date
    Jul 2003
    Posts
    4
    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

  4. #4
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    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.

    PHP Code:
    <?
    $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.
    ?>

  5. #5
    Junior Member
    Join Date
    Jul 2003
    Posts
    4
    Thanks a bunch for the comment lines. I think I understand what's going on now.
    Cheers

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center