Browse Source

Attempted to auto-detect port number in get_location()

Tyler Akins 25 years ago
parent
commit
8c33b4b434
1 changed files with 9 additions and 3 deletions
  1. 9 3
      functions/strings.php

+ 9 - 3
functions/strings.php

@@ -203,7 +203,7 @@
       #
       #   http://www.myhost.com/squirrelmail/src/login.php
    
-      global $PHP_SELF, $SERVER_NAME, $HTTPS, $HTTP_HOST;
+      global $PHP_SELF, $SERVER_NAME, $HTTPS, $HTTP_HOST, $HTTP_SERVER_VARS;
 
       // Get the path
       $path = substr($PHP_SELF, 0, strrpos($PHP_SELF, '/'));
@@ -214,13 +214,19 @@
         $proto = "https://";
       }
    
+      if ($HTTP_SERVER_VARS['SERVER_PORT']) {
+        if ($HTTP_SERVER_VARS['SERVER_PORT'] != 80) {
+            $port = ':' . $HTTP_SERVER_VARS['SERVER_PORT'];
+        }
+      }
+          
       // Get the hostname from the Host header or server config.
       // Fallback is to omit the server name and use a relative URI,
       // although this is not RFC 2616 compliant.
       if(isset($HTTP_HOST) && !empty($HTTP_HOST)) {
-        $location = $proto . $HTTP_HOST . $path;
+        $location = $proto . $HTTP_HOST . $port . $path;
       } else if(isset($SERVER_NAME) && !empty($SERVER_NAME)) {
-        $location = $proto . $SERVER_NAME . $path;
+        $location = $proto . $SERVER_NAME . $port . $path;
       } else {
         $location = $path;
       }