+// Extract host from script name
+function extractHostnameFromUrl (&$script) {
+ // Use default SERVER_URL by default... ;) So?
+ $url = getServerUrl();
+
+ // 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);
+ $url = $extract[0];
+ // Done extracting the URL :)
+ } // END - if
+
+ // Extract host name
+ $host = str_replace(array('http://', 'https://'), array('', ''), $url);
+
+ // Is there a slash at the end?
+ if (isInString('/', $host)) {
+ $host = substr($host, 0, strpos($host, '/'));
+ } // END - if
+
+ // Is there a double-dot in? (Means port number)
+ if (strpos($host, ':') !== FALSE) {
+ // Detected a double-dot
+ $hostArray = explode(':', $host);
+ $host = $hostArray[0];
+ } // END - if
+
+ // Generate relative URL
+ //* DEBUG: */ debugOutput('SCRIPT=' . $script);
+ if (substr(strtolower($script), 0, 7) == 'http://') {
+ // But only if http:// is in front!
+ $script = substr($script, (strlen($url) + 7));
+ } elseif (substr(strtolower($script), 0, 8) == 'https://') {
+ // Does this work?!
+ $script = substr($script, (strlen($url) + 8));
+ }
+
+ //* DEBUG: */ debugOutput('SCRIPT=' . $script);
+ if (substr($script, 0, 1) == '/') {
+ $script = substr($script, 1);
+ } // END - if
+
+ // Return host name
+ return $host;
+}
+
+// Adds a HTTP header to array
+function addHttpHeader ($header) {
+ // Send the header
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, ': header=' . $header);
+ array_push($GLOBALS['http_header'], trim($header));
+}
+
+// Flushes all HTTP headers
+function flushHttpHeaders () {
+ // Is the header already sent?
+ if (headers_sent()) {
+ // Then abort here
+ reportBug(__FUNCTION__, __LINE__, 'Headers already sent!');
+ } elseif ((!isset($GLOBALS['http_header'])) || (!is_array($GLOBALS['http_header']))) {
+ // Not set or not an array
+ reportBug(__FUNCTION__, __LINE__, 'Headers not set or not an array, isset()=' . isset($GLOBALS['http_header']) . ', please report this.');
+ }
+
+ // Flush all headers if found
+ foreach ($GLOBALS['http_header'] as $header) {
+ // Send a single header
+ header($header);
+ } // END - foreach
+
+ // Mark them as flushed
+ $GLOBALS['http_header'] = array();
+}
+