diff --git a/httprl.module b/httprl.module index 62635d5..7ae7dc1 100644 --- a/httprl.module +++ b/httprl.module @@ -90,6 +90,19 @@ function httprl_build_url_self($path = '', $detect_schema = FALSE) { } elseif (empty($ip)) { $ip = empty($_SERVER['SERVER_ADDR']) ? '127.0.0.1' : $_SERVER['SERVER_ADDR']; + // Check for IPv6. If IPv6 convert to IPv4 if possible. + if (strpos($ip, ':') !== FALSE) { + if ($_SERVER['SERVER_ADDR'] == '::1') { + $ip = "127.0.0.1"; + } + elseif (preg_match('/^::\d+.\d+.\d+.\d+$/', $ip)) { + $ip = substr($ip, 2); + } + elseif (!empty($_SERVER['HTTP_HOST'])) { + // Last option is to use the IP from the host name. + $ip = gethostbyname($_SERVER['HTTP_HOST']); + } + } } // Port.