Skip to content

Instantly share code, notes, and snippets.

@aaryadev
Created August 29, 2018 08:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aaryadev/ebb94a1dba9c947b764f1af25306adca to your computer and use it in GitHub Desktop.
Save aaryadev/ebb94a1dba9c947b764f1af25306adca to your computer and use it in GitHub Desktop.
Code igniter API Header setting for JSON output
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Api extends CI_Controller {
function __construct(){
parent:: __construct();
$this->output->set_header("Access-Control-Allow-Origin: * ");
$this->output->set_header("Access-Control-Expose-Headers: Access-Control-Allow-Origin");
$this->output->set_header("HTTP/1.0 200 OK");
$this->output->set_header("HTTP/1.1 200 OK");
$this->output->set_header('Last-Modified: '.gmdate('D, d M Y H:i:s', time()).' GMT');
$this->output->set_header("Cache-Control: no-store, no-cache, must-revalidate");
$this->output->set_header("Cache-Control: post-check=0, pre-check=0");
$this->output->set_header("Pragma: no-cache");
$this->output->set_content_type('application/json');
}
public function index(){
$this->output->set_output(json_encode($data));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment