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
} // 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
// 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];
- // 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);
($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) != '/')
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 () {