From 43f74c1f1e4667cff46e11f024565280dbd9c5d3 Mon Sep 17 00:00:00 2001 From: yehuda Date: Wed, 6 Mar 2019 11:15:29 +0200 Subject: Another try to optimize the hostname query --- Postman/PostmanUtils.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'Postman/PostmanUtils.php') diff --git a/Postman/PostmanUtils.php b/Postman/PostmanUtils.php index 8c7081f..7a443de 100644 --- a/Postman/PostmanUtils.php +++ b/Postman/PostmanUtils.php @@ -447,7 +447,7 @@ class PostmanUtils { } public static function getServerName() { - $result = 'localhost.localdomain'; + $host = 'localhost.localdomain'; if (isset($_SERVER) and array_key_exists('SERVER_NAME', $_SERVER)) { $host = $_SERVER['SERVER_NAME']; @@ -459,9 +459,18 @@ class PostmanUtils { // as final option - if ip returned or hostname without extension (not valid dns name) $extension = pathinfo( $host, PATHINFO_EXTENSION ); - if ( filter_var( $result, FILTER_VALIDATE_IP ) || empty( $extension ) ) { + if ( filter_var( $host, FILTER_VALIDATE_IP ) || empty( $extension ) ) { $siteurl = get_bloginfo('url'); - $host = parse_url($siteurl, PHP_URL_HOST); + $temp_host = parse_url( $siteurl, PHP_URL_HOST); + + $dnsr = dns_get_record( $temp_host, DNS_A ); + $ip = gethostbyname( $temp_host ); + + foreach ( $dnsr as $record ) { + if ( $record['host'] == $temp_host && $record['ip'] == $ip ) { + $host = $temp_host; + } + } } return str_replace('www.', '', $host ); -- cgit v1.2.3