CRM-12527 - Set http headers in CMS-compatible way
authorColeman Watts <coleman@civicrm.org>
Fri, 7 Aug 2015 20:23:57 +0000 (16:23 -0400)
committerColeman Watts <coleman@civicrm.org>
Fri, 7 Aug 2015 20:55:19 +0000 (16:55 -0400)
26 files changed:
CRM/Batch/Page/AJAX.php
CRM/Campaign/Page/AJAX.php
CRM/Contact/Page/AJAX.php
CRM/Contact/Page/ImageFile.php
CRM/Core/Controller.php
CRM/Core/Page/AJAX.php
CRM/Core/Page/AJAX/Attachment.php
CRM/Custom/Page/AJAX.php
CRM/Export/BAO/Export.php
CRM/Financial/BAO/ExportFormat.php
CRM/Financial/Page/AJAX.php
CRM/Group/Page/AJAX.php
CRM/Mailing/Page/Preview.php
CRM/Report/Form.php
CRM/Report/Utils/Report.php
CRM/Utils/ICalendar.php
CRM/Utils/JSON.php
CRM/Utils/PDF/Utils.php
CRM/Utils/REST.php
CRM/Utils/System.php
CRM/Utils/System/Base.php
CRM/Utils/System/Drupal.php
CRM/Utils/System/Drupal6.php
CRM/Utils/System/Drupal8.php
CRM/Utils/System/Joomla.php
CRM/Utils/System/UnitTests.php

index 434533e67812d94304325e4251d85394d7375dfe..864b38a882d9156c882ebafe09a8a79ab362aeba 100644 (file)
@@ -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();
   }
index 423e5903f695ced06135cdb786ff23c5ff2b9dc5..02ad12fd2f19e588938ae4b186a19843515a3bf7 100644 (file)
@@ -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();
   }
index feba0661a7ed82fe6684b4e1d4fee05b9b70f646..a2a9b3bd9c54559ebc3f2dce95ba5092186e3795 100644 (file)
@@ -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();
index 443b3ca706fa5e93d73b496d239f0942a92df034..13e4af98e889e74bee1ba1be18982e5af83f5077 100644 (file)
@@ -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);
   }
 
index 98aab731d91f6fdad44b5fee33eef74cc8523bef..4b437735718243fd01cc8fc0513bb344046d68b0 100644 (file)
@@ -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");
   }
 
   /**
index 7d6604ea832f44e703bf9c435ca8cc38e5d61874..a510c94a55b627b489a865926d427520bf12fe83 100644 (file)
@@ -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 = "<textarea>$output</textarea>";
@@ -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");
   }
 
 }
index 7aaf3cd5d899e2dc9909c30f47a9d830805966d9..d043a5f43b3de6947108614a452c94476cc0b806 100644 (file)
@@ -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");
index b4bc680cb04dab4ed46c3ad98a640e70a509c134..eabe16f097f1ec00e46ef4abb7fe1307949e2257 100644 (file)
@@ -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();
   }
index ecc9b1849992b05983d2ea5b0aa7757dff8107f3..c560444b4b537e2210255228f713ae48059b0fd3 100644 (file)
@@ -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);
         }
index ac035fbe004f11749571742cb758806c3ace0530..e0ffac1bbcb2ffdf28c5d6d7165768df898925a9 100644 (file)
@@ -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])));
index 907a4b20bf7b07eb3d29d4947c705a773dec9e9a..f8cfa05a78a6205f497a8a137baba66de7b44bd7 100644 (file)
@@ -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();
   }
index 6844ef559ecdd0c83d0dde238e8fe1085eaa8c45..aca4ddc1333b8bd4dddeb1d9bf63e71e448f58d0 100644 (file)
@@ -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();
     }
index cc615381aff5555b552d91bd047233d52b7fc60f..7b96ff1cfd6878c59211b22cef05ccc5d208bf8b 100644 (file)
@@ -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();
index 8c03314d19fd4547b31a94079f3fcb1631d3be06..b4aec7d9345833c7a9df1b896c9f06e97a80c04f 100644 (file)
@@ -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
index ca511b13b05cd03a1c96a5715a7755d6f271ab5a..74ce2c21c7ba46b655703fc65f8bfd78a69ed08e 100644 (file)
@@ -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();
   }
index 096ce70f7613bd45f648d32909ac526ec68b3af8..0f460658fd498a88c0b032d8e82232941f0f1a7a 100644 (file)
@@ -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;
index f210f1dfa6fcfc68fdd8dd9eed98b0f118f5c0a7..01e0b60bbf32f4fd108d0ad2a2611aad7c50c037 100644 (file)
@@ -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();
   }
index f2c9bd85588899f41ae18255cca136052f400bbd..62d592e5c2557b894715439b1aa13479e81d633c 100644 (file)
@@ -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();
       }
index 4bac9b7db502bf026e45019df4d33707e34e9bde..b5b3880ed46ae52a1cdff7e78393a25c091b253d 100644 (file)
@@ -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
index a9d1e3a901a7ce5bd1f2c2551b916c4efb3dab6c..3ea64b468137955b270e9b497aad68153f135b4a 100644 (file)
@@ -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);
+  }
+
 }
index 866aeeafed11b172cbb36a1179a544dc58fab961..dec96a5dbc370fc491f804b64879a2628fa5aea2 100644 (file)
@@ -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");
+  }
+
 }
index 105bab57df2488e3d751303d3f51cec22e66e1b4..c3f3921f945bfa6c08dd823b4db6ff9545f172e7 100644 (file)
@@ -773,4 +773,11 @@ AND    u.status = 1
     return $timezone;
   }
 
+  /**
+   * @inheritDoc
+   */
+  public function setHttpHeader($name, $value) {
+    drupal_add_http_header($name, $value);
+  }
+
 }
index 5d52afc3124aaf43432f5843eb2abc54c569c877..cd354b9357a9f85418faf632cd22bdbf8c93cd87 100644 (file)
@@ -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");
+  }
+
 }
index 7de4b715090be3d1352c345c37cb8eefa1f998e6..e824e5d31e1093a1fe36934ef41a3d5ce6164cd1 100644 (file)
@@ -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);
+  }
 }
index a8431f47b948a38c7b98f5bdc7f19fa27883317b..daa5c84964f5e1845f557d28806f45e8f9d1f14c 100644 (file)
@@ -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");
   }
 
   /**
index f2014b027f971beb65634ec53efee7ec597a1059..e24468a094396a9ac8c124ff1d453a67dccba9f7 100644 (file)
@@ -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");
   }
 
   /**