API16

JResponse/setHeader: Difference between revisions

From Joomla! Documentation

m clean up
m preparing for archive only
 
Line 4: Line 4:




{{subst:Description:JResponse/setHeader}}
 


===Syntax===
===Syntax===
Line 57: Line 57:




{{subst:SeeAlso:JResponse/setHeader}}
 


===Examples===
===Examples===
<CodeExamplesForm />
=== Code Examples ===
<dpl>
<dpl>
  noresultsheader=\n
  noresultsheader=\n
  category=setHeader
  category=setHeader
  category=JResponse
  category=JResponse
  category=CodeExample
  namespace=CodeExample
  category=MethodExample
  category=MethodExample
  include=*
  include=*
  format= ,,,
  format= ,,,
</dpl>
</dpl>

Latest revision as of 02:01, 25 March 2017

Description

Set a header



Syntax

static setHeader($name, $value, $replace=false)
Parameter Name Default Value Description
$name $name
$value $value
$replace false $replace

Defined in

libraries/joomla/environment/response.php

Importing

jimport( 'joomla.environment.response' );

Source Body

public static function setHeader($name, $value, $replace = false)
{
        $name   = (string) $name;
        $value  = (string) $value;

        if ($replace)
        {
                foreach ($GLOBALS['_JRESPONSE']->headers as $key => $header) {
                        if ($name == $header['name']) {
                                unset($GLOBALS['_JRESPONSE']->headers[$key]);
                        }
                }
        }

        $GLOBALS['_JRESPONSE']->headers[] = array(
                'name'  => $name,
                'value' => $value
        );
}



Examples

Code Examples