From: Roland Häder Date: Tue, 13 Sep 2011 16:06:27 +0000 (+0000) Subject: Some functions renamed: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=21b7860d55b9125cb4adb9b48511d6b1cf0cae20;p=mailer.git Some functions renamed: - sendHeader() and flushHeaders() renamed to addHttpHeader() and flushHttpHeaders(), these are only HTTP-related functions - Therefore they have been moved to proper library script --- diff --git a/inc/http-functions.php b/inc/http-functions.php index 85ae678a45..6877963cc3 100644 --- a/inc/http-functions.php +++ b/inc/http-functions.php @@ -46,16 +46,16 @@ function sendHttpHeaders () { $now = gmdate('D, d M Y H:i:s') . ' GMT'; // Send HTTP header - sendHeader('HTTP/1.1 ' . getHttpStatus()); + addHttpHeader('HTTP/1.1 ' . getHttpStatus()); // General headers for no caching - sendHeader('Expires: ' . $now); // RFC2616 - Section 14.21 - sendHeader('Last-Modified: ' . $now); - sendHeader('Cache-Control: no-store, no-cache, must-revalidate, pre-check=0, post-check=0, max-age=0'); // HTTP/1.1 - sendHeader('Pragma: no-cache'); // HTTP/1.0 - sendHeader('Connection: Close'); - sendHeader('Content-Type: ' . getContentType() . '; charset=UTF-8'); - sendHeader('Content-Language: ' . getLanguage()); + addHttpHeader('Expires: ' . $now); // RFC2616 - Section 14.21 + addHttpHeader('Last-Modified: ' . $now); + addHttpHeader('Cache-Control: no-store, no-cache, must-revalidate, pre-check=0, post-check=0, max-age=0'); // HTTP/1.1 + addHttpHeader('Pragma: no-cache'); // HTTP/1.0 + addHttpHeader('Connection: Close'); + addHttpHeader('Content-Type: ' . getContentType() . '; charset=UTF-8'); + addHttpHeader('Content-Language: ' . getLanguage()); } // Checks wether the URL is full-qualified (http[s]:// + hostname [+ request data]) @@ -773,5 +773,31 @@ function extractHostnameFromUrl (&$script) { return $host; } +// Adds a HTTP header to array +function addHttpHeader ($header) { + // Send the header + //* DEBUG: */ logDebugMessage(__FUNCTION__ . ': header=' . $header); + $GLOBALS['http_header'][] = trim($header); +} + +// Flushes all HTTP headers +function flushHttpHeaders () { + // Is the header already sent? + if (headers_sent()) { + // Then abort here + debug_report_bug(__FUNCTION__, __LINE__, 'Headers already sent!'); + } // END - if + + // Flush all headers if found + if ((isset($GLOBALS['http_header'])) && (is_array($GLOBALS['http_header']))) { + foreach ($GLOBALS['http_header'] as $header) { + header($header); + } // END - foreach + } // END - if + + // Mark them as flushed + $GLOBALS['http_header'] = array(); +} + // [EOF] ?> diff --git a/inc/modules/admin/what-logs.php b/inc/modules/admin/what-logs.php index 896073d960..e3ba9580c3 100644 --- a/inc/modules/admin/what-logs.php +++ b/inc/modules/admin/what-logs.php @@ -56,19 +56,19 @@ if (isGetRequestElementSet('access')) { // Set header if (substr($access, -3, 3) == 'log') { // Output header - sendHeader('Content-Type: text/plain'); + addHttpHeader('Content-Type: text/plain'); // Clean content clearOutputBuffer(); } elseif (substr($access, -3, 3) == '.gz') { // @TODO Fix content-type here - sendHeader('Content-Type: text/plain'); + addHttpHeader('Content-Type: text/plain'); // Clean content clearOutputBuffer(); } elseif (substr($access, -3, 3) == '.bz2') { // @TODO Fix content-type here - sendHeader('Content-Type: text/plain'); + addHttpHeader('Content-Type: text/plain'); // Clean content clearOutputBuffer(); diff --git a/inc/template-functions.php b/inc/template-functions.php index 2259ffc2e5..25f31b3e88 100644 --- a/inc/template-functions.php +++ b/inc/template-functions.php @@ -171,7 +171,7 @@ function outputHtml ($htmlCode, $newLine = true) { outputRawCode($GLOBALS['output']); } else { // And flush all headers - flushHeaders(); + flushHttpHeaders(); } } @@ -196,21 +196,21 @@ function compileFinalOutput () { $GLOBALS['output'] = gzencode($GLOBALS['output'], 9); // Add header - sendHeader('Content-Encoding: gzip'); + addHttpHeader('Content-Encoding: gzip'); } elseif (!empty($_SERVER['HTTP_ACCEPT_ENCODING']) && (isInStringIgnoreCase('deflate', $_SERVER['HTTP_ACCEPT_ENCODING']))) { // Compress it for HTTP deflate $GLOBALS['output'] = gzcompress($GLOBALS['output'], 9); // Add header - sendHeader('Content-Encoding: deflate'); + addHttpHeader('Content-Encoding: deflate'); } */ // Add final length - sendHeader('Content-Length: ' . strlen($GLOBALS['output'])); + addHttpHeader('Content-Length: ' . strlen($GLOBALS['output'])); // Flush all headers - flushHeaders(); + flushHttpHeaders(); } // Main compilation loop diff --git a/inc/wrapper-functions.php b/inc/wrapper-functions.php index 5dde76d70f..ce74b918bd 100644 --- a/inc/wrapper-functions.php +++ b/inc/wrapper-functions.php @@ -481,33 +481,6 @@ function copyFileVerified ($source, $dest, $chmod = '') { return $status; } -// Wrapper function for header() -// Send a header but checks before if we can do so -function sendHeader ($header) { - // Send the header - //* DEBUG: */ logDebugMessage(__FUNCTION__ . ': header=' . $header); - $GLOBALS['header'][] = trim($header); -} - -// Flushes all headers -function flushHeaders () { - // Is the header already sent? - if (headers_sent()) { - // Then abort here - debug_report_bug(__FUNCTION__, __LINE__, 'Headers already sent!'); - } // END - if - - // Flush all headers if found - if ((isset($GLOBALS['header'])) && (is_array($GLOBALS['header']))) { - foreach ($GLOBALS['header'] as $header) { - header($header); - } // END - foreach - } // END - if - - // Mark them as flushed - $GLOBALS['header'] = array(); -} - // Wrapper function for chmod() // @TODO Do some more sanity check here function changeMode ($FQFN, $mode) { @@ -1148,10 +1121,10 @@ function sendRawRedirect ($url) { (preg_match('|^Microsoft-IIS/(\d)\.\d$|', trim($_SERVER['SERVER_SOFTWARE']), $matches)) && ($matches[1] < 6)) { // Send the IIS header - sendHeader('Refresh: 0;url=' . $url); + addHttpHeader('Refresh: 0;url=' . $url); } else { // Send generic header - sendHeader('Location: ' . $url); + addHttpHeader('Location: ' . $url); } // Shutdown here