WordPress.org

Forums

Supporting X-Forwarded-For (2 posts)

  1. Veidit
    Member
    Posted 5 years ago #

    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();

  2. Veidit
    Member
    Posted 5 years ago #

    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

Topic Closed

This topic has been closed to new replies.

About this Topic