Skip to:
Content
Pages
Categories
Search
Top
Bottom

X-Forwarded-For to show as IP address

  • I’m using the Kakumei theme, and am located behind a load-balancer.

    All posts show the IP address as the IP address of the load-balancer rather than the poster. I know the load-balancer does send the poster’s IP address in the X-Forwarded-For HTTP Header field.

    Is it possible to get bbPress to pull out this IP address, rather than the load-balancer’s IP address?

Viewing 2 replies - 1 through 2 (of 2 total)

  • zaerl
    Participant

    @zaerl

    Locate the function bb_insert_post in file functions.bb-posts.php, then find the line:

    $ip_address = $_SERVER['REMOTE_ADDR'];

    The real (*cough*) IP of the user can be retrieved with this function:

    function get_real_ip()
    {
    $ip = '';
    $u = 'unknown';

    if(($ip = getenv('HTTP_CLIENT_IP')) && strcasecmp($ip, $u)) {}
    elseif(($ip = getenv('REMOTE_ADDR')) && strcasecmp($ip, $u)) {}
    elseif(($ip = getenv('HTTP_X_FORWARDED_FOR')) && strcasecmp($ip, $u)) {}
    elseif(isset($_SERVER['REMOTE_ADDR']) && ($ip = $_SERVER['REMOTE_ADDR']) && strcasecmp($ip, $u)) {}
    else return $u;

    return $ip;
    }


    zaerl
    Participant

    @zaerl

    Locate the function bb_insert_post in file functions.bb-posts.php, then find the line:

    $ip_address = $_SERVER['REMOTE_ADDR'];

    The real (*cough*) IP of the user can be retrieved with this function:

    function get_real_ip()
    {
    $ip = '';
    $u = 'unknown';

    if(($ip = getenv('HTTP_CLIENT_IP')) && strcasecmp($ip, $u)) {}
    elseif(($ip = getenv('REMOTE_ADDR')) && strcasecmp($ip, $u)) {}
    elseif(($ip = getenv('HTTP_X_FORWARDED_FOR')) && strcasecmp($ip, $u)) {}
    elseif(isset($_SERVER['REMOTE_ADDR']) && ($ip = $_SERVER['REMOTE_ADDR']) && strcasecmp($ip, $u)) {}
    else return $u;

    return $ip;
    }

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.
Skip to toolbar