Habari\Utils::get_ip PHP Méthode

get_ip() public static méthode

Get the remote IP address, but try and take into account users who are behind proxies, whether they know it or not.
public static get_ip ( string $default = '0.0.0.0' ) : string
$default string a default IP address
Résultat string The client's IP address.
    public static function get_ip($default = '0.0.0.0')
    {
        // @todo in particular HTTP_X_FORWARDED_FOR could be a comma-separated list of IPs that have handled it, the client being the left-most. we should handle that...
        $keys = array('HTTP_CLIENT_IP', 'HTTP_FORWARDED', 'HTTP_X_FORWARDED', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_CLUSTER_CLIENT_IP', 'REMOTE_ADDR');
        $return = '';
        foreach ($keys as $key) {
            if (isset($_SERVER[$key])) {
                $return = $_SERVER[$key];
            }
        }
        // make sure whatever IP we got was valid
        $valid = filter_var($return, FILTER_VALIDATE_IP);
        if ($valid === false) {
            return $default;
        } else {
            return $return;
        }
    }