Forwarding an IP address within a File get contents

Discussion in 'PHP' started by sm9ai, Nov 19, 2009.

  1. #1
    Hi,

    Slight issues, I have two machines, A and B.

    A simplified version is that...
    Machine B serves a webpage. (The page must live on this server)
    Machine A gets the webpage using a file get contents and displays the page to the end user.

    This works fine. However the log files of B always show machine A as the IP address, which is correct. However it would be much better if machine B had the users IP address within the Log files. Is this possible? and if so, how?

    Thanks
     
    sm9ai, Nov 19, 2009 IP
  2. org

    org Peon

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I don't know exactly how your script works, but I would do it like that

    Server A:
    first you get the ip of the user:
    if ($_SERVER['HTTP_X_FORWARD_FOR']) {
    $ip = $_SERVER['HTTP_X_FORWARD_FOR'];
    } else {
    $ip = $_SERVER['REMOTE_ADDR'];
    }
    PHP:
    then send the ip to Server B with a parameter:
    $data = file_get_contents('http://www.serverb.com/content.php?ip='.$ip); 
    PHP:
    Server B:
    There you go, here is the IP of the user. Now you can add it to your log!
    $ip = $_GET['ip']
    PHP:
     
    org, Nov 19, 2009 IP
  3. travelmoth

    travelmoth Active Member

    Messages:
    153
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #3
    log files of B still show the ip of A........I think there is no way to forward an ip address....
     
    travelmoth, Nov 19, 2009 IP