Introduced detectServerProtocol() to fully support HTTPS and more use of isFullQualif...
authorRoland Haeder <roland@mxchange.org>
Mon, 28 Mar 2016 12:55:01 +0000 (14:55 +0200)
committerRoland Haeder <roland@mxchange.org>
Mon, 28 Mar 2016 12:55:01 +0000 (14:55 +0200)
Signed-off-by: Roland Häder <roland@mxchange.org>
inc/config-global.php
inc/functions.php
inc/http-functions.php
inc/install-functions.php
inc/wrapper-functions.php

index 9880b8f9a83e57630a7fd5fa78c50b33d898e9af..e34c4cfb9d33f5d6c2574199d5a3d3af6e115590 100644 (file)
@@ -66,7 +66,7 @@ foreach (array('config', 'wrapper', 'template', 'module', 'inc', 'http') as $inc
 include($path . 'inc/functions.php');
 
 // Auto-detection of URL
 include($path . 'inc/functions.php');
 
 // Auto-detection of URL
-$URL = 'http://' . detectServerName() . str_replace(chr(92), '/', dirname($_SERVER['PHP_SELF']));
+$URL = detectServerProtocol() . '://' . detectServerName() . str_replace(chr(92), '/', dirname($_SERVER['PHP_SELF']));
 while (substr($URL, -1, 1) == '/') { $URL = substr($URL, 0, -1); }
 
 // Initialize the configuration
 while (substr($URL, -1, 1) == '/') { $URL = substr($URL, 0, -1); }
 
 // Initialize the configuration
index 4469fb25e0f9f2a27e22a4d5cf7d9f3d4fc96909..a240205c2816c7bfa2355f19448b205e4ff41496 100644 (file)
@@ -2083,7 +2083,7 @@ function encodeUrl ($url, $outputMode = '0') {
        } // END - if
 
        // Add {?URL?} ?
        } // END - if
 
        // Add {?URL?} ?
-       if ((substr($url, 0, strlen(getUrl())) != getUrl()) && (substr($url, 0, 7) != '{?URL?}') && (substr($url, 0, 7) != 'http://') && (substr($url, 0, 8) != 'https://')) {
+       if ((substr($url, 0, strlen(getUrl())) != getUrl()) && (substr($url, 0, 7) != '{?URL?}') && (!isFullQualifiedUrl($url))) {
                // Add it
                $url = '{?URL?}/' . $url;
        } // END - if
                // Add it
                $url = '{?URL?}/' . $url;
        } // END - if
index 042e4b72e8bfb62cce0c88f9f5903abc7646a5a2..654c05e2907bdebf4b7beb7d4cc86e83f1826dcf 100644 (file)
@@ -644,11 +644,13 @@ function extractHostnameFromUrl (&$script) {
        // Is this URL valid?
        if (substr($script, 0, 7) == 'http://') {
                // Use the hostname from script URL as new hostname
        // Is this URL valid?
        if (substr($script, 0, 7) == 'http://') {
                // Use the hostname from script URL as new hostname
-               $url = substr($script, 7);
-               $extract = explode('/', $url);
+               $extract = explode('/', substr($script, 7));
                $url = $extract[0];
                $url = $extract[0];
-               // Done extracting the URL :)
-       } // END - if
+       } elseif (substr($script, 0, 8) == 'https://') {
+               // Use the hostname from script URL as new hostname
+               $extract = explode('/', substr($script, 8));
+               $url = $extract[0];
+       }
 
        // Extract host name
        $host = str_replace(array('http://', 'https://'), array('', ''), $url);
 
        // Extract host name
        $host = str_replace(array('http://', 'https://'), array('', ''), $url);
index 7c205e24813a08aaeeab28960fff1b17a251122e..a0ac6850a6ff8d6affeb9fab5e7530d341572915 100644 (file)
@@ -474,7 +474,7 @@ function isInstallerBaseUrlValid ($value) {
                ($value == getUrl())
        || (
                // Starts with http:// or https:// ?
                ($value == getUrl())
        || (
                // Starts with http:// or https:// ?
-               ((substr($value, 0, 7) == 'http://') || (substr($value, 0, 8) == 'https://'))
+               (isFullQualifiedUrl($value))
        &&
                // Has no trailing slash?
                (substr($value, -1, 1) != '/')
        &&
                // Has no trailing slash?
                (substr($value, -1, 1) != '/')
index 4520489da1ffc09a355846e58f2018a46c3034ad..b3a63292626d341f5764167b638f1b39db7f8feb 100644 (file)
@@ -293,6 +293,24 @@ function detectServerName () {
        return (getenv('SERVER_NAME'));
 }
 
        return (getenv('SERVER_NAME'));
 }
 
+// Detects server protocol (http/s)
+function detectServerProtocol () {
+       // Is cache there?
+       if (!isset($GLOBALS[__FUNCTION__])) {
+               // Default is HTTP
+               $GLOBALS[__FUNCTION__] = 'http';
+
+               // Are some specific fields set?
+               if (((isset($_SERVER['HTTPS'])) && (strtolower($_SERVER['HTTPS']) == 'on')) || ((isset($_SERVER['HTTP_X_FORWARDED_PROTO'])) && (strtolower($_SERVER['HTTP_X_FORWARDED_PROTO']) == 'https'))) {
+                       // Switch to HTTPS
+                       $GLOBALS[__FUNCTION__] = 'https';
+               } // END - if
+       } // END - if
+
+       // Return cached value
+       return $GLOBALS[__FUNCTION__];
+}
+
 // Removes any  existing www. from SERVER_NAME. This is very silly but enough
 // for our purpose here.
 function detectDomainName () {
 // Removes any  existing www. from SERVER_NAME. This is very silly but enough
 // for our purpose here.
 function detectDomainName () {