dcsimg
A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: keeping count on visitors?

  1. #1
    Senior Member SirN's Avatar
    Join Date
    Apr 2003
    Location
    Sweden
    Posts
    142

    keeping count on visitors?

    Hi all,

    I want to get the ip-address of the visitors (or a way to have a count on visitors) I'm thinking about saving to an XML and keep count - simply put!

    can you help?
    Last edited by SirN; 10-05-2005 at 11:22 AM. Reason: wrong title

  2. #2
    A Senior Newbie - How Odd ForumNewbie's Avatar
    Join Date
    Mar 2003
    Posts
    590

    Not Really 3DFA, but Hopefully a Useful Answer

    Hi,

    I spent weeks trying to do the same when trying to track user activity on the darts game. eg. If a user's connectivity dropped briefly, it was supposed to reconnect using the IP address to identify the user. If I remember right, you can't get the IP address from within Flash, or even javascript on the webpage. I had to use server side scripting.

    In a nutshell, I discovered it was harder than it ought to be ! Personally, I would use a free tracker like http://www.freewebcounter.com . It's not perfect, but much easier than doing it yourself !

    If you are intent on doing this you could try something like the following, which did work in the end:
    Set up a PHP server.
    Set up a mySQL database with a table called 'usertrack' in a database called 'usertrack'. Set up 5 text fields in it for the _ip, _date, _time, _host, and the _page viewed. Imagine for this example that the mySQL database has a user ID of 'user' and a password of 'password'.
    Create a variable in your swf for _page which identifies what page the user is viewing.
    Have your swf call a PHP script with this code in it:

    PHP Code:
    <?php
        $_page 
    $_POST['_page'];
                 
    $_ip="$REMOTE_ADDR";
        
    $_host=gethostbyaddr($_ip);
        if (
    $_page == null)
            {
            
    $_page="$HTTP_REFERER";
            }    
        
    $_datedate("Ymd");
        
    $_timedate("His");
        
    $dbconnection=@mysql_connect("localhost","user","password");
        echo (
    $dbconnection);
        if (!
    $dbconnection
        {
            echo(
    "No SQL SERVER AVAILABLE");
              exit();
        }
        
    mysql_select_db("usertrack",$dbconnection);
        if (! @
    mysql_select_db("usertrack") ) 
        {
            echo( 
    "NO DATABASE AVAILABLE" );
            exit();
        }
        
    $page="index";
        
    $sql="insert into usertrack values ('$_ip', '$_date', '$_time', '$_page', '$_host')";
        echo (
    $sql);
        if ( 
    mysql_query($sql) );
            {
            echo(
    "<P>Update affected " mysql_affected_rows() . " rows.</P>");
            }
    ?>
    The problem is that if the PHP server is behind a proxy server, the IP address reported is that of the proxy server and not the client, so you then have to modify the proxy server to pass the client IP address instead. Search on the net for something called a 'webresponsemodifier' for how to get round this.

    I'm sure there are other ways, but this worked for me. If you prefer using PHP to write an XML file instead of to populate a database, or if you can translate this to an ASP script writing to XML, this may be better for your needs.

    Best of luck.

    Morgan
    Last edited by ForumNewbie; 10-10-2005 at 07:39 PM. Reason: Adding more info and correcting stuff
    Please note that my domain has changed to http://www.morganmultinational.com

  3. #3
    Senior Member SirN's Avatar
    Join Date
    Apr 2003
    Location
    Sweden
    Posts
    142
    Thanks for the reply, I'm going to use freewebcounter!

  4. #4
    A Senior Newbie - How Odd ForumNewbie's Avatar
    Join Date
    Mar 2003
    Posts
    590
    Probably wise !

    I was tearing my hair out whilst doing it myself. There's probably an easy way, but I never found what it was.

    I've just written up a semi-tutorial on how this can be done using mySQL and PHP in another thread. Hopefully it will spare somebody some pain !

    Morgan
    Please note that my domain has changed to http://www.morganmultinational.com

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