Horde_Registry::remoteHost PHP Method

remoteHost() public method

Returns information about the remote host.
Since: 2.17.0
public remoteHost ( ) : object
return object An object with the following properties:
  - addr: (string) Remote IP address.
  - host: (string) Remote hostname (if resolvable; otherwise, this value
          is identical to 'addr').
  - proxy: (boolean) True if this user is connecting through a proxy.
    public function remoteHost()
    {
        global $injector;
        $out = new stdClass();
        $dns = $injector->getInstance('Net_DNS2_Resolver');
        $old_error = error_reporting(0);
        if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
            $remote_path = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
            $out->addr = $remote_path[0];
            $out->proxy = true;
        } else {
            $out->addr = $_SERVER['REMOTE_ADDR'];
            if (!empty($_SERVER['REMOTE_HOST'])) {
                $out->host = $_SERVER['REMOTE_HOST'];
            }
            $out->proxy = false;
        }
        if ($dns && !isset($out->host)) {
            $out->host = $out->addr;
            try {
                if ($response = $dns->query($out->addr, 'PTR')) {
                    foreach ($response->answer as $val) {
                        if (isset($val->ptrdname)) {
                            $out->host = $val->ptrdname;
                            break;
                        }
                    }
                }
            } catch (Net_DNS2_Exception $e) {
            }
        } elseif (!isset($out->host)) {
            $out->host = gethostbyaddr($out->addr);
        }
        error_reporting($old_error);
        return $out;
    }