0

i get request from android and IOS clients. I store the request in an array. then i encode it to JSON. Now i want to sent only the JSON data in my HTTP header. How to do that? Currently its sending the html page in response i want to send only json encoded data in 200 OK header.

Below is my code:

public function index()
{


    $request = array(
'request' => $this->input->get('request'),
'device_id' => $this->input->get('device_id'),
'launch_date'=> $this->input->get('launch_date'),
'allowed_hours'=>$this->input->get('allowed_hours'),
'site_id'=> $this->input->get('site_id'),
'product'=>$this->input->get('product'),
'software_version'=> $this->input->get('software_version'),
'platform_os'=> $this->input->get('platform_os'),
'platform'=> $this->input->get('platform'),
'platform_model'=> $this->input->get('platform_model')
    );

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





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





    }
    }

MY response:

A PHP Error was encountered Severity: Notice

Message: Undefined index: request

Filename: admin/license.php

Line Number: 22

A PHP Error was encountered Severity: Notice

Message: Undefined index: allowed_hours

Filename: admin/license.php

Line Number: 25

A PHP Error was encountered Severity: Notice

Message: Undefined index: allowed_hours

Filename: admin/license.php

Line Number: 40

{"response_code":200,"device_id":"70D0D01FBAD2","allowed_hours":null,"product":"mlc","prov_ur":null}array(10) { ["Host"]=> string(14) "192.168.50.123" ["Connection"]=> 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,/;q=0.8" ["Upgrade-Insecure-Requests"]=> string(1) "1" ["User-Agent"]=> string(110) "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.111 Safari/537.36" ["Accept-Encoding"]=> string(19) "gzip, deflate, sdch" ["Accept-Language"]=> string(14) "en-US,en;q=0.8" ["Cookie"]=> 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" }

Rajan
  • 2,427
  • 10
  • 51
  • 111

1 Answers1

0

this is not a header problem your array do not have "allowed_hours"

 Message: Undefined index: allowed_hours 

you can change your code like this

$allowed_hours = "";


if(!empty($this->input->get('allowed_hours'))){
$allowed_hours = $this->input->get('allowed_hours');
}
$response = array(
    'response_code' =>200 ,
    'device_id'=> $this->input->get('device_id'),
    'allowed_hours'=> $allowed_hours,
    'product'=>'mlc',
    'prov_ur'=>NULL 
);
synan54
  • 658
  • 6
  • 16