From: Coleman Watts Date: Fri, 7 Aug 2015 20:23:57 +0000 (-0400) Subject: CRM-12527 - Set http headers in CMS-compatible way X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=d42a224c4ec248744f5b0adc30ef0ddc899df559;p=civicrm-core.git CRM-12527 - Set http headers in CMS-compatible way --- diff --git a/CRM/Batch/Page/AJAX.php b/CRM/Batch/Page/AJAX.php index 434533e678..864b38a882 100644 --- a/CRM/Batch/Page/AJAX.php +++ b/CRM/Batch/Page/AJAX.php @@ -114,7 +114,7 @@ class CRM_Batch_Page_AJAX { 'links', ); } - header('Content-Type: application/json'); + CRM_Utils_System::setHttpHeader('Content-Type', 'application/json'); echo CRM_Utils_JSON::encodeDataTableSelector($batches, $sEcho, $iTotal, $iFilteredTotal, $selectorElements); CRM_Utils_System::civiExit(); } diff --git a/CRM/Campaign/Page/AJAX.php b/CRM/Campaign/Page/AJAX.php index 423e5903f6..02ad12fd2f 100644 --- a/CRM/Campaign/Page/AJAX.php +++ b/CRM/Campaign/Page/AJAX.php @@ -360,7 +360,7 @@ class CRM_Campaign_Page_AJAX { $iFilteredTotal = $iTotal; - header('Content-Type: application/json'); + CRM_Utils_System::setHttpHeader('Content-Type', 'application/json'); echo CRM_Utils_JSON::encodeDataTableSelector($searchRows, $sEcho, $iTotal, $iFilteredTotal, $selectorElements); CRM_Utils_System::civiExit(); } @@ -660,7 +660,7 @@ class CRM_Campaign_Page_AJAX { $iFilteredTotal = $iTotal; - header('Content-Type: application/json'); + CRM_Utils_System::setHttpHeader('Content-Type', 'application/json'); echo CRM_Utils_JSON::encodeDataTableSelector($searchRows, $sEcho, $iTotal, $iFilteredTotal, $selectorElements); CRM_Utils_System::civiExit(); } @@ -764,7 +764,7 @@ class CRM_Campaign_Page_AJAX { $iFilteredTotal = $iTotal; - header('Content-Type: application/json'); + CRM_Utils_System::setHttpHeader('Content-Type', 'application/json'); echo CRM_Utils_JSON::encodeDataTableSelector($searchRows, $sEcho, $iTotal, $iFilteredTotal, $selectorElements); CRM_Utils_System::civiExit(); } @@ -863,7 +863,7 @@ class CRM_Campaign_Page_AJAX { $iFilteredTotal = $iTotal; - header('Content-Type: application/json'); + CRM_Utils_System::setHttpHeader('Content-Type', 'application/json'); echo CRM_Utils_JSON::encodeDataTableSelector($searchRows, $sEcho, $iTotal, $iFilteredTotal, $selectorElements); CRM_Utils_System::civiExit(); } diff --git a/CRM/Contact/Page/AJAX.php b/CRM/Contact/Page/AJAX.php index feba0661a7..a2a9b3bd9c 100644 --- a/CRM/Contact/Page/AJAX.php +++ b/CRM/Contact/Page/AJAX.php @@ -295,7 +295,7 @@ class CRM_Contact_Page_AJAX { } public static function groupTree() { - header('Content-Type: application/json'); + CRM_Utils_System::setHttpHeader('Content-Type', 'application/json'); $gids = CRM_Utils_Type::escape($_GET['gids'], 'String'); echo CRM_Contact_BAO_GroupNestingCache::json($gids); CRM_Utils_System::civiExit(); @@ -305,7 +305,7 @@ class CRM_Contact_Page_AJAX { * Delete custom value. */ public static function deleteCustomValue() { - header('Content-Type: text/plain'); + CRM_Utils_System::setHttpHeader('Content-Type', 'text/plain'); $customValueID = CRM_Utils_Type::escape($_REQUEST['valueID'], 'Positive'); $customGroupID = CRM_Utils_Type::escape($_REQUEST['groupID'], 'Positive'); @@ -370,7 +370,7 @@ class CRM_Contact_Page_AJAX { $userEmail ) = CRM_Contact_BAO_Contact_Location::getEmailDetails($contactID); - header('Content-Type: text/plain'); + CRM_Utils_System::setHttpHeader('Content-Type', 'text/plain'); if ($userEmail) { echo $userEmail; } @@ -713,7 +713,7 @@ LIMIT {$offset}, {$rowCount} } } - header('Content-Type: application/json'); + CRM_Utils_System::setHttpHeader('Content-Type', 'application/json'); echo CRM_Utils_JSON::encodeDataTableSelector($searchRows, $sEcho, $iTotal, $iFilteredTotal, $selectorElements); CRM_Utils_System::civiExit(); diff --git a/CRM/Contact/Page/ImageFile.php b/CRM/Contact/Page/ImageFile.php index 443b3ca706..13e4af98e8 100644 --- a/CRM/Contact/Page/ImageFile.php +++ b/CRM/Contact/Page/ImageFile.php @@ -83,11 +83,11 @@ class CRM_Contact_Page_ImageFile extends CRM_Core_Page { header('HTTP/1.0 403 Forbidden'); return; } - header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', CRM_Utils_Time::getTimeRaw() + $ttl)); - header("Content-Type: $mimeType"); - header("Content-Disposition: inline; filename=\"" . basename($file) . "\""); - header("Cache-Control: max-age=$ttl, public"); - header('Pragma: public'); + CRM_Utils_System::setHttpHeader('Expires', gmdate('D, d M Y H:i:s \G\M\T', CRM_Utils_Time::getTimeRaw() + $ttl)); + CRM_Utils_System::setHttpHeader("Content-Type", $mimeType); + CRM_Utils_System::setHttpHeader("Content-Disposition", "inline; filename=\"" . basename($file) . "\""); + CRM_Utils_System::setHttpHeader("Cache-Control", "max-age=$ttl, public"); + CRM_Utils_System::setHttpHeader('Pragma', 'public'); readfile($file); } diff --git a/CRM/Core/Controller.php b/CRM/Core/Controller.php index 98aab731d9..4b43773571 100644 --- a/CRM/Core/Controller.php +++ b/CRM/Core/Controller.php @@ -692,13 +692,13 @@ class CRM_Core_Controller extends HTML_QuickForm_Controller { */ public function setWord($fileName = NULL) { //Mark as a CSV file. - header('Content-Type: application/vnd.ms-word'); + CRM_Utils_System::setHttpHeader('Content-Type', 'application/vnd.ms-word'); //Force a download and name the file using the current timestamp. if (!$fileName) { $fileName = 'Contacts_' . $_SERVER['REQUEST_TIME'] . '.doc'; } - header("Content-Disposition: attachment; filename=Contacts_$fileName"); + CRM_Utils_System::setHttpHeader("Content-Disposition", "attachment; filename=Contacts_$fileName"); } /** @@ -706,14 +706,14 @@ class CRM_Core_Controller extends HTML_QuickForm_Controller { */ public function setExcel($fileName = NULL) { //Mark as an excel file. - header('Content-Type: application/vnd.ms-excel'); + CRM_Utils_System::setHttpHeader('Content-Type', 'application/vnd.ms-excel'); //Force a download and name the file using the current timestamp. if (!$fileName) { $fileName = 'Contacts_' . $_SERVER['REQUEST_TIME'] . '.xls'; } - header("Content-Disposition: attachment; filename=Contacts_$fileName"); + CRM_Utils_System::setHttpHeader("Content-Disposition", "attachment; filename=Contacts_$fileName"); } /** diff --git a/CRM/Core/Page/AJAX.php b/CRM/Core/Page/AJAX.php index 7d6604ea83..a510c94a55 100644 --- a/CRM/Core/Page/AJAX.php +++ b/CRM/Core/Page/AJAX.php @@ -189,7 +189,7 @@ class CRM_Core_Page_AJAX { // CRM-11831 @see http://www.malsup.com/jquery/form/#file-upload if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') { - header('Content-Type: application/json'); + CRM_Utils_System::setHttpHeader('Content-Type', 'application/json'); } else { $output = ""; @@ -209,9 +209,9 @@ class CRM_Core_Page_AJAX { // Encourage browsers to cache for a long time - 1 year $ttl = 60 * 60 * 24 * 364; } - header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', time() + $ttl)); - header('Content-Type: application/javascript'); - header("Cache-Control: max-age=$ttl, public"); + CRM_Utils_System::setHttpHeader('Expires', gmdate('D, d M Y H:i:s \G\M\T', time() + $ttl)); + CRM_Utils_System::setHttpHeader('Content-Type', 'application/javascript'); + CRM_Utils_System::setHttpHeader('Cache-Control', "max-age=$ttl, public"); } } diff --git a/CRM/Core/Page/AJAX/Attachment.php b/CRM/Core/Page/AJAX/Attachment.php index 7aaf3cd5d8..d043a5f43b 100644 --- a/CRM/Core/Page/AJAX/Attachment.php +++ b/CRM/Core/Page/AJAX/Attachment.php @@ -135,7 +135,7 @@ class CRM_Core_Page_AJAX_Attachment { if ($isError) { $sapi_type = php_sapi_name(); if (substr($sapi_type, 0, 3) == 'cgi') { - header("Status: 500 Internal Server Error"); + CRM_Utils_System::setHttpHeader("Status", "500 Internal Server Error"); } else { header("HTTP/1.1 500 Internal Server Error"); diff --git a/CRM/Custom/Page/AJAX.php b/CRM/Custom/Page/AJAX.php index b4bc680cb0..eabe16f097 100644 --- a/CRM/Custom/Page/AJAX.php +++ b/CRM/Custom/Page/AJAX.php @@ -62,7 +62,7 @@ class CRM_Custom_Page_AJAX { 'class', ); - header('Content-Type: application/json'); + CRM_Utils_System::setHttpHeader('Content-Type', 'application/json'); echo CRM_Utils_JSON::encodeDataTableSelector($options, $sEcho, $iTotal, $iFilteredTotal, $selectorElements); CRM_Utils_System::civiExit(); } diff --git a/CRM/Export/BAO/Export.php b/CRM/Export/BAO/Export.php index ecc9b18499..c560444b4b 100644 --- a/CRM/Export/BAO/Export.php +++ b/CRM/Export/BAO/Export.php @@ -1251,11 +1251,11 @@ INSERT INTO {$componentTable} SELECT distinct gc.contact_id FROM civicrm_group_c $errorFileName = $parserName::errorFileName($type); $saveFileName = $parserName::saveFileName($type); if (!empty($errorFileName) && !empty($saveFileName)) { - header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); - header('Content-Description: File Transfer'); - header('Content-Type: text/csv'); - header('Content-Length: ' . filesize($errorFileName)); - header('Content-Disposition: attachment; filename=' . $saveFileName); + CRM_Utils_System::setHttpHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0'); + CRM_Utils_System::setHttpHeader('Content-Description', 'File Transfer'); + CRM_Utils_System::setHttpHeader('Content-Type', 'text/csv'); + CRM_Utils_System::setHttpHeader('Content-Length', filesize($errorFileName)); + CRM_Utils_System::setHttpHeader('Content-Disposition', 'attachment; filename=' . $saveFileName); readfile($errorFileName); } diff --git a/CRM/Financial/BAO/ExportFormat.php b/CRM/Financial/BAO/ExportFormat.php index ac035fbe00..e0ffac1bbc 100644 --- a/CRM/Financial/BAO/ExportFormat.php +++ b/CRM/Financial/BAO/ExportFormat.php @@ -155,9 +155,9 @@ class CRM_Financial_BAO_ExportFormat { $zip = $config->customFileUploadDir . 'Financial_Transactions_' . date('YmdHis') . '.zip'; $result = $this->createZip($this->_downloadFile, $zip, TRUE); if ($result) { - header('Content-Type: application/zip'); - header('Content-Disposition: attachment; filename=' . CRM_Utils_File::cleanFileName(basename($zip))); - header('Content-Length: ' . filesize($zip)); + CRM_Utils_System::setHttpHeader('Content-Type', 'application/zip'); + CRM_Utils_System::setHttpHeader('Content-Disposition', 'attachment; filename=' . CRM_Utils_File::cleanFileName(basename($zip))); + CRM_Utils_System::setHttpHeader('Content-Length', '' . filesize($zip)); ob_clean(); flush(); readfile($config->customFileUploadDir . CRM_Utils_File::cleanFileName(basename($zip))); @@ -166,9 +166,9 @@ class CRM_Financial_BAO_ExportFormat { } } else { - header('Content-Type: text/plain'); - header('Content-Disposition: attachment; filename=' . CRM_Utils_File::cleanFileName(basename($this->_downloadFile[0]))); - header('Content-Length: ' . filesize($this->_downloadFile[0])); + CRM_Utils_System::setHttpHeader('Content-Type', 'text/plain'); + CRM_Utils_System::setHttpHeader('Content-Disposition', 'attachment; filename=' . CRM_Utils_File::cleanFileName(basename($this->_downloadFile[0]))); + CRM_Utils_System::setHttpHeader('Content-Length', '' . filesize($this->_downloadFile[0])); ob_clean(); flush(); readfile($config->customFileUploadDir . CRM_Utils_File::cleanFileName(basename($this->_downloadFile[0]))); diff --git a/CRM/Financial/Page/AJAX.php b/CRM/Financial/Page/AJAX.php index 907a4b20bf..f8cfa05a78 100644 --- a/CRM/Financial/Page/AJAX.php +++ b/CRM/Financial/Page/AJAX.php @@ -460,7 +460,7 @@ class CRM_Financial_Page_AJAX { 'action', ); - header('Content-Type: application/json'); + CRM_Utils_System::setHttpHeader('Content-Type', 'application/json'); echo CRM_Utils_JSON::encodeDataTableSelector($financialitems, $sEcho, $iTotal, $iFilteredTotal, $selectorElements); CRM_Utils_System::civiExit(); } diff --git a/CRM/Group/Page/AJAX.php b/CRM/Group/Page/AJAX.php index 6844ef559e..aca4ddc133 100644 --- a/CRM/Group/Page/AJAX.php +++ b/CRM/Group/Page/AJAX.php @@ -112,7 +112,7 @@ class CRM_Group_Page_AJAX { if (!empty($params['is_unit_test'])) { return array($groups, $iFilteredTotal); } - header('Content-Type: application/json'); + CRM_Utils_System::setHttpHeader('Content-Type', 'application/json'); echo CRM_Utils_JSON::encodeDataTableSelector($groups, $sEcho, $iTotal, $iFilteredTotal, $selectorElements); CRM_Utils_System::civiExit(); } diff --git a/CRM/Mailing/Page/Preview.php b/CRM/Mailing/Page/Preview.php index cc615381af..7b96ff1cfd 100644 --- a/CRM/Mailing/Page/Preview.php +++ b/CRM/Mailing/Page/Preview.php @@ -92,11 +92,11 @@ class CRM_Mailing_Page_Preview extends CRM_Core_Page { ); if ($type == 'html') { - header('Content-Type: text/html; charset=utf-8'); + CRM_Utils_System::setHttpHeader('Content-Type', 'text/html; charset=utf-8'); print $mime->getHTMLBody(); } else { - header('Content-Type: text/plain; charset=utf-8'); + CRM_Utils_System::setHttpHeader('Content-Type', 'text/plain; charset=utf-8'); print $mime->getTXTBody(); } CRM_Utils_System::civiExit(); diff --git a/CRM/Report/Form.php b/CRM/Report/Form.php index 8c03314d19..b4aec7d934 100644 --- a/CRM/Report/Form.php +++ b/CRM/Report/Form.php @@ -3142,7 +3142,7 @@ WHERE cg.extends IN ('" . implode("','", $this->_customGroupExtends) . "') AND //Load the image $chart = imagecreatefrompng($uploadUrl); //convert it into formatted png - header('Content-type: image/png'); + CRM_Utils_System::setHttpHeader('Content-type', 'image/png'); //overwrite with same image imagepng($chart, $uploadImg); //delete the object diff --git a/CRM/Report/Utils/Report.php b/CRM/Report/Utils/Report.php index ca511b13b0..74ce2c21c7 100644 --- a/CRM/Report/Utils/Report.php +++ b/CRM/Report/Utils/Report.php @@ -223,11 +223,11 @@ WHERE inst.report_id = %1"; */ public static function export2csv(&$form, &$rows) { //Mark as a CSV file. - header('Content-Type: text/csv'); + CRM_Utils_System::setHttpHeader('Content-Type', 'text/csv'); //Force a download and name the file using the current timestamp. $datetime = date('Ymd-Gi', $_SERVER['REQUEST_TIME']); - header('Content-Disposition: attachment; filename=Report_' . $datetime . '.csv'); + CRM_Utils_System::setHttpHeader('Content-Disposition', 'attachment; filename=Report_' . $datetime . '.csv'); echo self::makeCsv($form, $rows); CRM_Utils_System::civiExit(); } diff --git a/CRM/Utils/ICalendar.php b/CRM/Utils/ICalendar.php index 096ce70f76..0f460658fd 100644 --- a/CRM/Utils/ICalendar.php +++ b/CRM/Utils/ICalendar.php @@ -109,16 +109,15 @@ class CRM_Utils_ICalendar { public static function send($calendar, $content_type = 'text/calendar', $charset = 'us-ascii', $fileName = NULL, $disposition = NULL) { $config = CRM_Core_Config::singleton(); $lang = $config->lcMessages; - header("Content-Language: $lang"); - // header( "Content-Type: $content_type; charset=$charset; profile=\"ICalendar\"" ); - header("Content-Type: $content_type; charset=$charset"); + CRM_Utils_System::setHttpHeader("Content-Language", $lang); + CRM_Utils_System::setHttpHeader("Content-Type", "$content_type; charset=$charset"); if ($content_type == 'text/calendar') { - header('Content-Length: ' . strlen($calendar)); - header("Content-Disposition: $disposition; filename=\"$fileName\""); - header("Pragma: no-cache"); - header("Expires: 0"); - header("Cache-Control: no-cache, must-revalidate"); + CRM_Utils_System::setHttpHeader('Content-Length', strlen($calendar)); + CRM_Utils_System::setHttpHeader("Content-Disposition", "$disposition; filename=\"$fileName\""); + CRM_Utils_System::setHttpHeader("Pragma", "no-cache"); + CRM_Utils_System::setHttpHeader("Expires", "0"); + CRM_Utils_System::setHttpHeader("Cache-Control", "no-cache, must-revalidate"); } echo $calendar; diff --git a/CRM/Utils/JSON.php b/CRM/Utils/JSON.php index f210f1dfa6..01e0b60bbf 100644 --- a/CRM/Utils/JSON.php +++ b/CRM/Utils/JSON.php @@ -43,7 +43,7 @@ class CRM_Utils_JSON { * @param mixed $input */ public static function output($input) { - header('Content-Type: application/json'); + CRM_Utils_System::setHttpHeader('Content-Type', 'application/json'); echo json_encode($input); CRM_Utils_System::civiExit(); } diff --git a/CRM/Utils/PDF/Utils.php b/CRM/Utils/PDF/Utils.php index f2c9bd8558..62d592e5c2 100644 --- a/CRM/Utils/PDF/Utils.php +++ b/CRM/Utils/PDF/Utils.php @@ -233,8 +233,8 @@ class CRM_Utils_PDF_Utils { return $pdf; } else { - header('Content-Type: application/pdf'); - header('Content-Disposition: attachment; filename="' . $fileName . '"'); + CRM_Utils_System::setHttpHeader('Content-Type', 'application/pdf'); + CRM_Utils_System::setHttpHeader('Content-Disposition', 'attachment; filename="' . $fileName . '"'); echo $pdf; } } @@ -400,9 +400,9 @@ class CRM_Utils_PDF_Utils { $len = strlen($buf); if ($echo) { - header('Content-type: application/pdf'); - header("Content-Length: $len"); - header("Content-Disposition: inline; filename={$output}.pdf"); + CRM_Utils_System::setHttpHeader('Content-type', 'application/pdf'); + CRM_Utils_System::setHttpHeader("Content-Length", $len); + CRM_Utils_System::setHttpHeader("Content-Disposition", "inline; filename={$output}.pdf"); echo $buf; CRM_Utils_System::civiExit(); } diff --git a/CRM/Utils/REST.php b/CRM/Utils/REST.php index 4bac9b7db5..b5b3880ed4 100644 --- a/CRM/Utils/REST.php +++ b/CRM/Utils/REST.php @@ -145,7 +145,7 @@ class CRM_Utils_REST { } if (!empty($requestParams['json'])) { - header('Content-Type: application/json'); + CRM_Utils_System::setHttpHeader('Content-Type', 'application/json'); if (!empty($requestParams['prettyprint'])) { // Used by the api explorer return self::jsonFormated(array_merge($result)); @@ -451,7 +451,7 @@ class CRM_Utils_REST { * @param $pearError */ public static function fatal($pearError) { - header('Content-Type: text/xml'); + CRM_Utils_System::setHttpHeader('Content-Type', 'text/xml'); $error = array(); $error['code'] = $pearError->getCode(); $error['error_message'] = $pearError->getMessage(); @@ -484,7 +484,7 @@ class CRM_Utils_REST { $smarty = CRM_Core_Smarty::singleton(); CRM_Utils_System::setTitle("$entity::$tplfile inline $tpl"); if (!$smarty->template_exists($tpl)) { - header("Status: 404 Not Found"); + CRM_Utils_System::setHttpHeader("Status", "404 Not Found"); die ("Can't find the requested template file templates/$tpl"); } if (array_key_exists('id', $_GET)) {// special treatmenent, because it's often used diff --git a/CRM/Utils/System.php b/CRM/Utils/System.php index a9d1e3a901..3ea64b4681 100644 --- a/CRM/Utils/System.php +++ b/CRM/Utils/System.php @@ -410,7 +410,7 @@ class CRM_Utils_System { )); } - header('Location: ' . $url); + self::setHttpHeader('Location', $url); self::civiExit(); } @@ -813,8 +813,8 @@ class CRM_Utils_System { ) { $now = gmdate('D, d M Y H:i:s') . ' GMT'; - header('Content-Type: ' . $mimeType); - header('Expires: ' . $now); + self::setHttpHeader('Content-Type', $mimeType); + self::setHttpHeader('Expires', $now); // lem9 & loic1: IE need specific headers $isIE = strstr($_SERVER['HTTP_USER_AGENT'], 'MSIE'); @@ -825,13 +825,13 @@ class CRM_Utils_System { $fileString = "filename=\"{$name}\""; } if ($isIE) { - header("Content-Disposition: inline; $fileString"); - header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); - header('Pragma: public'); + self::setHttpHeader("Content-Disposition", "inline; $fileString"); + self::setHttpHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0'); + self::setHttpHeader('Pragma', 'public'); } else { - header("Content-Disposition: $disposition; $fileString"); - header('Pragma: no-cache'); + self::setHttpHeader("Content-Disposition", "$disposition; $fileString"); + self::setHttpHeader('Pragma', 'no-cache'); } if ($output) { @@ -1880,4 +1880,12 @@ class CRM_Utils_System { return NULL; } + /** + * @param string $name + * @param string $value + */ + public static function setHttpHeader($name, $value) { + CRM_Core_Config::singleton()->userSystem->setHttpHeader($name, $value); + } + } diff --git a/CRM/Utils/System/Base.php b/CRM/Utils/System/Base.php index 866aeeafed..dec96a5dbc 100644 --- a/CRM/Utils/System/Base.php +++ b/CRM/Utils/System/Base.php @@ -740,4 +740,12 @@ abstract class CRM_Utils_System_Base { public function appendCoreResources(&$list) { } + /** + * @param string $name + * @param string $value + */ + public function setHttpHeader($name, $value) { + header("$name: $value"); + } + } diff --git a/CRM/Utils/System/Drupal.php b/CRM/Utils/System/Drupal.php index 105bab57df..c3f3921f94 100644 --- a/CRM/Utils/System/Drupal.php +++ b/CRM/Utils/System/Drupal.php @@ -773,4 +773,11 @@ AND u.status = 1 return $timezone; } + /** + * @inheritDoc + */ + public function setHttpHeader($name, $value) { + drupal_add_http_header($name, $value); + } + } diff --git a/CRM/Utils/System/Drupal6.php b/CRM/Utils/System/Drupal6.php index 5d52afc312..cd354b9357 100644 --- a/CRM/Utils/System/Drupal6.php +++ b/CRM/Utils/System/Drupal6.php @@ -741,4 +741,11 @@ class CRM_Utils_System_Drupal6 extends CRM_Utils_System_DrupalBase { return $timezone; } + /** + * @inheritDoc + */ + public function setHttpHeader($name, $value) { + drupal_set_header("$name: $value"); + } + } diff --git a/CRM/Utils/System/Drupal8.php b/CRM/Utils/System/Drupal8.php index 7de4b71509..e824e5d31e 100644 --- a/CRM/Utils/System/Drupal8.php +++ b/CRM/Utils/System/Drupal8.php @@ -551,4 +551,11 @@ class CRM_Utils_System_Drupal8 extends CRM_Utils_System_DrupalBase { $cache_backend->deleteAll(); } } + + /** + * @inheritDoc + */ + public function setHttpHeader($name, $value) { + \Symfony\Component\HttpFoundation\Response->headers->set($name, $value); + } } diff --git a/CRM/Utils/System/Joomla.php b/CRM/Utils/System/Joomla.php index a8431f47b9..daa5c84964 100644 --- a/CRM/Utils/System/Joomla.php +++ b/CRM/Utils/System/Joomla.php @@ -456,7 +456,7 @@ class CRM_Utils_System_Joomla extends CRM_Utils_System_Base { */ public function logout() { session_destroy(); - header("Location:index.php"); + CRM_Utils_System::setHttpHeader("Location", "index.php"); } /** diff --git a/CRM/Utils/System/UnitTests.php b/CRM/Utils/System/UnitTests.php index f2014b027f..e24468a094 100644 --- a/CRM/Utils/System/UnitTests.php +++ b/CRM/Utils/System/UnitTests.php @@ -162,7 +162,7 @@ class CRM_Utils_System_UnitTests extends CRM_Utils_System_Base { */ public function logout() { session_destroy(); - header("Location:index.php"); + CRM_Utils_System::setHttpHeader("Location", "index.php"); } /**