public static function getIpAddress()
    {
        // check for shared internet/ISP IP
        if (isset($_SERVER['HTTP_CLIENT_IP']) && self::validateIp($_SERVER['HTTP_CLIENT_IP'])) {
            return $_SERVER['HTTP_CLIENT_IP'];
        }

        // check for IPs passing through proxies
        if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
            // check if multiple ips exist in var
            if (strpos($_SERVER['HTTP_X_FORWARDED_FOR'], ',') !== false) {
                $iplist = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
                foreach ($iplist as $ip) {
                    if (self::validateIp($ip)) {
                        return $ip;
                    }
                }
            } else {
                if (self::validateIp($_SERVER['HTTP_X_FORWARDED_FOR'])) {
                    return $_SERVER['HTTP_X_FORWARDED_FOR'];
                }
            }
        }
        if (isset($_SERVER['HTTP_X_FORWARDED']) && self::validateIp($_SERVER['HTTP_X_FORWARDED'])) {
            return $_SERVER['HTTP_X_FORWARDED'];
        }
        if (isset($_SERVER['HTTP_X_CLUSTER_CLIENT_IP']) && self::validateIp($_SERVER['HTTP_X_CLUSTER_CLIENT_IP'])) {
            return $_SERVER['HTTP_X_CLUSTER_CLIENT_IP'];
        }
        if (isset($_SERVER['HTTP_FORWARDED_FOR']) && self::validateIp($_SERVER['HTTP_FORWARDED_FOR'])) {
            return $_SERVER['HTTP_FORWARDED_FOR'];
        }
        if (isset($_SERVER['HTTP_FORWARDED']) && self::validateIp($_SERVER['HTTP_FORWARDED'])) {
            return $_SERVER['HTTP_FORWARDED'];
        }
        // return unreliable ip since all else failed
        return isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : 'unknown';
    }
public static function getIpAddress()
    {
        // check for shared internet/ISP IP
        if (isset($_SERVER['HTTP_CLIENT_IP']) && self::validateIp($_SERVER['HTTP_CLIENT_IP'])) {
            return $_SERVER['HTTP_CLIENT_IP'];
        }

        // check for IPs passing through proxies
        if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
            // check if multiple ips exist in var
            if (strpos($_SERVER['HTTP_X_FORWARDED_FOR'], ',') !== false) {
                $iplist = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
                foreach ($iplist as $ip) {
                    if (self::validateIp($ip)) {
                        return $ip;
                    }
                }
            } else {
                if (self::validateIp($_SERVER['HTTP_X_FORWARDED_FOR'])) {
                    return $_SERVER['HTTP_X_FORWARDED_FOR'];
                }
            }
        }
        if (isset($_SERVER['HTTP_X_FORWARDED']) && self::validateIp($_SERVER['HTTP_X_FORWARDED'])) {
            return $_SERVER['HTTP_X_FORWARDED'];
        }
        if (isset($_SERVER['HTTP_X_CLUSTER_CLIENT_IP']) && self::validateIp($_SERVER['HTTP_X_CLUSTER_CLIENT_IP'])) {
            return $_SERVER['HTTP_X_CLUSTER_CLIENT_IP'];
        }
        if (isset($_SERVER['HTTP_FORWARDED_FOR']) && self::validateIp($_SERVER['HTTP_FORWARDED_FOR'])) {
            return $_SERVER['HTTP_FORWARDED_FOR'];
        }
        if (isset($_SERVER['HTTP_FORWARDED']) && self::validateIp($_SERVER['HTTP_FORWARDED'])) {
            return $_SERVER['HTTP_FORWARDED'];
        }
        // return unreliable ip since all else failed
        return isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : 'unknown';
    }
public static function getIpAddress ( ) { // check for shared internet/ISP IP
 if ( isset ( $ _SERVER [ 'HTTP_CLIENT_IP' ] ) && self :: validateIp ( $ _SERVER [ 'HTTP_CLIENT_IP' ] ) ) { return $ _SERVER [ 'HTTP_CLIENT_IP' ] ; } // check for IPs passing through proxies
 if ( isset ( $ _SERVER [ 'HTTP_X_FORWARDED_FOR' ] ) ) { // check if multiple ips exist in var
 if ( strpos ( $ _SERVER [ 'HTTP_X_FORWARDED_FOR' ] , ',' ) !== false ) { $ iplist = explode ( ',' , $ _SERVER [ 'HTTP_X_FORWARDED_FOR' ] ) ; foreach ( $ iplist as $ ip ) { if ( self :: validateIp ( $ ip ) ) { return $ ip ; } } } else { if ( self :: validateIp ( $ _SERVER [ 'HTTP_X_FORWARDED_FOR' ] ) ) { return $ _SERVER [ 'HTTP_X_FORWARDED_FOR' ] ; } } } if ( isset ( $ _SERVER [ 'HTTP_X_FORWARDED' ] ) && self :: validateIp ( $ _SERVER [ 'HTTP_X_FORWARDED' ] ) ) { return $ _SERVER [ 'HTTP_X_FORWARDED' ] ; } if ( isset ( $ _SERVER [ 'HTTP_X_CLUSTER_CLIENT_IP' ] ) && self :: validateIp ( $ _SERVER [ 'HTTP_X_CLUSTER_CLIENT_IP' ] ) ) { return $ _SERVER [ 'HTTP_X_CLUSTER_CLIENT_IP' ] ; } if ( isset ( $ _SERVER [ 'HTTP_FORWARDED_FOR' ] ) && self :: validateIp ( $ _SERVER [ 'HTTP_FORWARDED_FOR' ] ) ) { return $ _SERVER [ 'HTTP_FORWARDED_FOR' ] ; } if ( isset ( $ _SERVER [ 'HTTP_FORWARDED' ] ) && self :: validateIp ( $ _SERVER [ 'HTTP_FORWARDED' ] ) ) { return $ _SERVER [ 'HTTP_FORWARDED' ] ; } // return unreliable ip since all else failed
 return isset ( $ _SERVER [ 'REMOTE_ADDR' ] ) ? $ _SERVER [ 'REMOTE_ADDR' ] : 'unknown' ; }
Retrieves the best guess of the client's actual IP address.
Takes into account numerous HTTP proxy headers due to variations
in how different ISPs handle IP addresses in headers between hops.
Retrieves the best guess of the client s actual IP address . Takes into account numerous HTTP proxy headers due to variations in how different ISPs handle IP addresses in headers between hops .