• A long time ago (in a support forum far far away) I asked about support for X-Forwarded-For.

    My question is if this is something that could be solved via a plugin or do I need to play around with my wp-config.conf

    I guess that we need to change $_SERVER[‘REMOTE_ADDR’]; recives it’s variable?

    Perhaps something like this?
    function getRemoteAddress() {
    $hostname = $_SERVER[‘REMOTE_ADDR’];

    $headers = apache_request_headers();
    foreach($headers as $k => $v) {
    if(strcasecmp($k, “x-forwarded-for”))
    continue;

    $hostname = explode(“,”, $v);
    $hostname = trim($hostname[0]);
    break;
    }

    return $hostname;
    }

    $_SERVER[“REMOTE_ADDR”] = getRemoteAddress();

Viewing 1 replies (of 1 total)
  • Thread Starter veidit

    (@veidit)

    function getRemoteAddress() {
            $hostname = $_SERVER['REMOTE_ADDR'];
    
            $headers = apache_request_headers();
            foreach($headers as $k => $v) {
                    if(strcasecmp($k, "x-forwarded-for"))
                            continue;
    
                    $hostname = explode(",", $v);
                    $hostname = trim($hostname[0]);
                    break;
            }
    
            return $hostname;
    }
    
    $_SERVER["REMOTE_ADDR"] = getRemoteAddress();

    Forgot to markup the code correctly

Viewing 1 replies (of 1 total)
  • The topic ‘Supporting X-Forwarded-For’ is closed to new replies.