Support » Plugin: Geo Redirect » [Plugin: Geo Redirect] Incorrect (or empty) visitor IP address (REMOTE_ADDR) on certain servers

  • Resolved 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;

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

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

    Many thanks!

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


    Great solution! Included in next release! Thanks!


    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. Everything is ok. He finds my IP and for that IP there are geo informations in the GeoIP.dat

    Result is empty -> nothing changes

    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 ) {
    $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.