• Resolved ade11

    (@ade11)


    Excellent plugin, exactly what several of our clients were looking for, and it works almost perfectly, except on our live servers.

    As it turns out, sometimes a server doesn’t return the visitor’s IP in $_SERVER[‘REMOTE_ADDR’]. Also sometimes it may return a list. It may be behind a proxy, or in a live cluster or some such, and use different $_SERVER variables for the visitor’s IP.

    In line 32 of your geo-redirect.php you have;

    $this->ip = $_SERVER['REMOTE_ADDR'];

    On our live servers, this will fail. Our senior developers have come against this before, and have provided a solution. If we simply replace your code above with this little bit of code below, your plugin works perfectly, even on these more complex server setups;

    $ip=$_SERVER['REMOTE_ADDR'];
    if (!empty($_SERVER['HTTP_CLIENT_IP'])) {               // check ip from share internet
    	$ip=$_SERVER['HTTP_CLIENT_IP'];
    } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {   // to check ip is pass from proxy
    	$ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
    }
    $ips = explode(",", $ip);
    $this->ip=$ips[0];

    Any chance you can incorporate this or similar into your next release?

    Many thanks!

    http://wordpress.org/extend/plugins/geographical-redirect/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Artem Platonov

    (@ladrower)

    Great solution! Included in next release! Thanks!

    Hi,

    We included the latest version of the plugin (3.3) where the improvement above has been integrated. We now have a new/further problem:

    Let’s get through the script

    1. $_SERVER[‘REMOTE_ADDR’]:
    1. Everything is ok. He finds my IP and for that IP there are geo informations in the GeoIP.dat

    2. $_SERVER[‘HTTP_CLIENT_IP’])
    Result is empty -> nothing changes

    3. $_SERVER[‘HTTP_X_FORWARDED_FOR’])
    The problem starts: the script finds out that “my IP” is a proxy-ip and get’s now my “real ip behind the proxy”.

    So why is that a problem?
    If HTTP_CLIENT_IP or HTTP_X_FORWARDED_FOR returns an IP without geiInformations $ip gets overwritten without success.

    For that I changed the script:

    private function getClientIP()
    {
    $ip = $_SERVER['REMOTE_ADDR'];
    if (!empty($_SERVER['HTTP_CLIENT_IP']) && strlen(geoip_country_code_by_addr($this->gi,$_SERVER['HTTP_CLIENT_IP'])) != 0 ) {
    $ip = $_SERVER['HTTP_CLIENT_IP'];
    }
    elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']) && strlen(geoip_country_code_by_addr($this->gi,$_SERVER['HTTP_X_FORWARDED_FOR'])) != 0 ) {
    $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
    }
    $ips = explode(",", $ip);
    return $ips[0];
    }

    So what do you think?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Plugin: Geo Redirect] Incorrect (or empty) visitor IP address (REMOTE_ADDR) on certain servers’ is closed to new replies.