• I modified the get_ip function in wp-power-stats.php as below because this was not working for IPv6 addresses when a valid IPv4 address was available later in one of the header keys. This was causing issues with get_insert_data because a null $ip was being used and returned.

    Proper support for IPv6 is probably needed if there is database tracking based on IP!

    protected static function get_ip()
    {
    $newip = “”;
    $header_keys = array(‘HTTP_CLIENT_IP’, ‘HTTP_X_FORWARDED_FOR’, ‘HTTP_X_FORWARDED’, ‘HTTP_X_CLUSTER_CLIENT_IP’, ‘HTTP_FORWARDED_FOR’, ‘HTTP_FORWARDED’, ‘REMOTE_ADDR’);

    foreach ($header_keys as $key) {
    if (array_key_exists($key, $_SERVER) === true) {
    foreach (explode(‘,’, $_SERVER[$key]) as $ip) {
    $ip = filter_var(trim($ip), FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE);
    if (isset($ip) && !empty($ip)) { $newip = $ip; }
    }
    }
    }

    return $newip;
    }

    • This topic was modified 6 years, 8 months ago by rvry.
    • This topic was modified 6 years, 8 months ago by rvry.
  • The topic ‘get_ip() function’ is closed to new replies.