Welcome, Guest
  • Author Topic: PHP ip address  (Read 1746 times)

    Ifalldown

    • Server what's that
    • *
    • Posts: 12
      • View Profile
      • Email
    PHP ip address
    « on: 04/01/10, 18:21 »
    I'm designing a login/registration form with the typical user/pasword authentication. What I want to do is also check the ip address as part of the authentication process but running into a problem gathering the ip address. I've tried PHP with no luck. I'm sure the problem is bettween chair and keyboard.

    I seen the remoting version on the flash-db which is excellent but I would like to attempt this with PHP first. I'm a baby step type. I've tried all the PHP methods I could muster and hoping maybe one of you have some suggestions.   

    For now I'm simply writing to a .text file.

    Ronald Wernecke

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 6203
      • View Profile
      • Professional Support
      • Email
    Re: PHP ip address
    « Reply #1 on: 04/02/10, 02:43 »
    try this:

    $_SERVER['SERVER_ADDR']

    The $_SERVER array tells you a lot about this current connection ;)

    Have a look into the PHP manual about these arrays - there are some more.
    happy flashing
    8)
    Ronald

    Ifalldown

    • Server what's that
    • *
    • Posts: 12
      • View Profile
      • Email
    Re: PHP ip address
    « Reply #2 on: 04/02/10, 07:36 »
    Hi Ronald,

    The ip address is writing to the .text file already but I can't seem to display the content of the text file.  Here is my PHP;


    <?php
     
    {
                    $filename = "xxx.txt";
              $fp = fopen( $filename,"r");
       fclose( $fp );

       $IP = $REMOTE_ADDR;

       $Input = "IP:$ipaddress<b>$IP</b>";

       $New = "$Input$OldData";

       $fp = fopen( $filename,"w");
       if(!$fp) die("&ipaddress=unable to write $filename ......&");
       fwrite($fp, $New, 100);

       fclose( $fp );
    }


       $filename = "xxx.txt";
       $fp    = fopen( $filename,"r");
       $Data    = fread($fp, 100);
       fclose( $fp );
          
       exit;
          
    ?>

    .text file content;

    IP:<b>69.14.234.228</b>

    AS to retrience the data;

    ipData = new LoadVars()
    ipData.load("http://xxx.com/address.php",0);








    Ronald Wernecke

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 6203
      • View Profile
      • Professional Support
      • Email
    Re: PHP ip address
    « Reply #3 on: 04/02/10, 11:33 »
    hm - if dont write anyhing to output, you will not see soemthing ;)

    Code: [Select]
    echo "data=".$Data;

    will wrtie the content to the variable data in your LoadVars object, wher you can process it further, or display in your movie clip
    happy flashing
    8)
    Ronald

    Ifalldown

    • Server what's that
    • *
    • Posts: 12
      • View Profile
      • Email
    Re: PHP ip address
    « Reply #4 on: 04/02/10, 22:41 »
    Thanks responsding Ronald. I am still unable to retrieve the data from the textfile. Below is the PHP with the "echo" but I'm not sure I'm placing it right or writing the script correctly. Maybe the entire PHP is not complete.

    <?php
     
    {
                    $filename = "xxx.txt";
              $fp = fopen( $filename,"r");
               fclose( $fp );
       
       $IP = $REMOTE_ADDR;
                 
       $Input = "IP:$IP";
       $New = "$Input$OldData";

       $fp = fopen( $filename,"w");
       if(!$fp) die("&IP=unable to write $filename ......&");
       fwrite($fp, $New, 100);

       fclose( $fp );
       
       }

    {
       $filename = "xxx.txt";
                   $fp = fopen( $filename,"r");
              $Data = fread($fp, 100);
       fclose( $fp );
       echo "ID:=".$IP;
             
       exit;
       }
          
    ?>

    I wish I was more advanced but that's wishful thinking. Perhaps you could point out where I'm falling down.

    Ronald Wernecke

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 6203
      • View Profile
      • Professional Support
      • Email
    Re: PHP ip address
    « Reply #5 on: 04/03/10, 02:21 »
    remove the colon:

    "ID=".$IP;

    then you will find the IP-Address in your LoadVars as ipData.ID;

    Be aware, you have to wait for the data event to be fired, before you can read the variable.

    Best to start: look into the loading and saving tutorials - there you'll find everything.
    happy flashing
    8)
    Ronald

    Ifalldown

    • Server what's that
    • *
    • Posts: 12
      • View Profile
      • Email
    Re: PHP ip address
    « Reply #6 on: 04/03/10, 09:32 »
    Hi Ronald,

    Thank you so much for your help, working great!. I'm glad you mentioned the " data event ".