summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoryehudah <yehudah@b8457f37-d9ea-0310-8a92-e5e31aec5664>2018-10-04 09:07:46 +0000
committeryehudah <yehudah@b8457f37-d9ea-0310-8a92-e5e31aec5664>2018-10-04 09:07:46 +0000
commit1b6339dcea96ad9114b01b23d5f2237508369b99 (patch)
tree49ff6c1cab93c4e832273f41001a720ea504111c
parentb691bb40966dad32bb242659e5f7f8d0812e7808 (diff)
downloadPost-SMTP-1b6339dcea96ad9114b01b23d5f2237508369b99.zip
* Serverhostname has a few issues in not shared hosting - cross fingers
-rw-r--r--Postman/PostmanUtils.php36
1 files changed, 10 insertions, 26 deletions
diff --git a/Postman/PostmanUtils.php b/Postman/PostmanUtils.php
index 8d5cd46..5405b79 100644
--- a/Postman/PostmanUtils.php
+++ b/Postman/PostmanUtils.php
@@ -445,37 +445,21 @@ class PostmanUtils {
$result = 'localhost.localdomain';
if (isset($_SERVER) and array_key_exists('SERVER_NAME', $_SERVER)) {
- $result = $_SERVER['SERVER_NAME'];
+ $host = $_SERVER['SERVER_NAME'];
} elseif (function_exists('gethostname') and gethostname() !== false) {
- $result = gethostname();
+ $host = gethostname();
} elseif (php_uname('n') !== false) {
- $result = php_uname('n');
+ $host = php_uname('n');
}
- if ( $result !== 'localhost.localdomain' ) {
- // get the current result ip
- $ip = gethostbyname($result);
-
- // dns query failed
- if ( $ip == $result ) {
- return $result;
- }
-
- // get the current ip hostname - reverse dns
- $host = gethostbyaddr($ip);
-
- // dns query failed
- if ( $host == $ip ) {
- return $result;
- }
-
- // if hostname is not equal to the result set the ptr
- if ( $result !== $host ) {
- $result = $host;
- }
- }
+ // 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 ) ) {
+ $siteurl = get_bloginfo('url');
+ $host = parse_url($siteurl, PHP_URL_HOST);
+ }
- return $result;
+ return str_replace('www.', '', $host );
}
public static function getHost( $url ) {