How to send custom HTTP header in response?
<p>I want to send json data in my HTTP Header.</p>

<p>I am using Codeigniter PHP, so I did this in my controller:</p>

<pre><code>header('Content-Type: application/json');'
</code></pre>

<p>This is my code:</p>

<pre><code>$request = array(

    'request' =&gt; $_GET['request'],
    'device_id' =&gt; $_GET['device_id'],
    'launch_date'=&gt; $_GET['launch_date'],
    'allowed_hours'=&gt;$_GET['allowed_hours'],
    'site_id'=&gt;$_GET['site_id'],
    'product'=&gt;$_GET['product'],
    'software_version'=&gt;$_GET['software_version'],
    'platform_os'=&gt;$_GET['platform_os'],
    'platform'=&gt;$_GET['platform'],
    'platform_model'=&gt;$_GET['platform_model']

     );
$response = array(
    'response_code' =&gt;200 ,
    'device_id'=&gt;$_GET['device_id'],
    'allowed_hours'=&gt;$_GET['allowed_hours'],
    'product'=&gt;'mlc',
    'prov_ur'=&gt;NULL 
);

header('Content-Type: application/json');
echo json_encode( $response );
</code></pre>

<p>But when I print my header I get</p>

<blockquote>
  <p></p>
  
  A PHP Error was encountered
  
  <p><p>Severity: Notice</p> <p>Message:  Undefined index: request</p>
  <p>Filename: admin/license.php</p> <p>Line Number: 22</p></p>
  
  <p></p>
  
  A PHP Error was encountered
  
  <p><p>Severity: Notice</p> <p>Message:  Undefined index:
  allowed_hours</p> <p>Filename: admin/license.php</p> <p>Line Number:
  25</p></p>
  
  <p></p>
  
  A PHP Error was encountered
  
  <p><p>Severity: Notice</p> <p>Message:  Undefined index:
  allowed_hours</p> <p>Filename: admin/license.php</p> <p>Line Number:
  40</p></p>
  
  <p>
  {"response_code":200,"device_id":"70D0D01FBAD2","allowed_hours":null,"product":"mlc","prov_ur":null}array(10)
  {   ["Host"]=>   string(14) "192.168.50.123"   ["Connection"]=><br>
  string(10) "keep-alive"   ["Cache-Control"]=>   string(9) "max-age=0" 
  ["Accept"]=>   string(74)
  "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,<em>/</em>;q=0.8"
  ["Upgrade-Insecure-Requests"]=>   string(1) "1"   ["User-Agent"]=><br>
  string(110) "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36
  (KHTML, like Gecko) Chrome/47.0.2526.111 Safari/537.36"<br>
  ["Accept-Encoding"]=>   string(19) "gzip, deflate, sdch"<br>
  ["Accept-Language"]=>   string(14) "en-US,en;q=0.8"   ["Cookie"]=><br>
  string(518)
  "cisession=OhhBBhVodwwf7Tb55AVsU32ClMS5cgmxBl15WHA%2BrGnvo1kiK%2B67BWeAuJVSV2MY25zZd0riHC9cyx9fiigiBuqkPMT%2FKE9d6et%2FXaE3F7I59P9%2FEzy5byQ5nEkJq5xwXoH1I7%2B7v62cQL21%2Bjfnk3AwIy4luM7N51IUuTqg7TxunoZFD1gJO84r8degY1imNpmDk2W%2FjsQPn9bQpkWJ9KVMxxViFDaELEU0rIfYmif%2BdvXjK9W%2Fj7iWQxZYE9ZGazgBTKlLO%2BJZHNdPrdmGPFTzTUROZdffpF%2Bb25bRMPEJsZ9CE2mdVuSn%2FEu678utd0lcd9bh%2BDbTDikrHP4jBFOLbZfWKT%2F9r5GkMBrLBl%2BlvPx9RbAq%2FIsjeA1V7c6JYf41TO1bG2XKT14QFHm8m0qY8HCal%2B%2BR8tZe9i3zy24%3Dcfc459942e4ef82a5554257216a19d621f446a25"
  ["If-Modified-Since"]=>   string(29) "Thu, 01 Jan 1970 00:00:00 GMT" }</p>
</blockquote>

<pre><code>{"response_code":200,"device_id":"70D0D01FBAD2","allowed_hours":null,"product":"mlc","prov_ur":null}
</code></pre>

<p>in my response. I don't want to send other data in my HTTP header response.</p>

<p><strong>Upadted Code as per CI</strong></p>

<pre><code>public function index()
{
    $request = array(
        'request' =&gt; $this-&gt;get('request'),
        'device_id' =&gt; $this-&gt;get('device_id'),
        'launch_date'=&gt; $this-&gt;get('launch_date'),
        'allowed_hours'=&gt;$this-&gt;get('allowed_hours'),
        'site_id'=&gt; $this-&gt;get('site_id'),
        'product'=&gt;$this-&gt;get('product'),
        'software_version'=&gt; $this-&gt;get('software_version'),
        'platform_os'=&gt; $this-&gt;get('platform_os'),
        'platform'=&gt; $this-&gt;get('platform'),
        'platform_model'=&gt; $this-&gt;get('platform_model')
    );

    $response = array(
        'response_code' =&gt;200 ,
        'device_id'=&gt; $this-&gt;get('device_id'),
        'allowed_hours'=&gt; $this-&gt;get('allowed_hours'),
        'product'=&gt;'mlc',
        'prov_ur'=&gt;NULL 
    );

    $this-&gt;output-&gt;set_content_type('Content-Type: application/json');

    return $this-&gt;output
    -&gt;set_content_type('Content-Type: application/json')
    -&gt;set_output(json_encode($response));

    echo $response;

}
</code></pre>