syedrakib syedrakib - 2 years ago 97
PHP Question

Access-Control-Allow-Origin is not showing up in response headers from codeigniter

My Codeigniter file says

$CI->output->set_header("Access-Control-Allow-Origin: *");
$CI->output->set_header("Access-Control-Expose-Headers: Access-Control-Allow-Origin");
echo json_encode(array("city" => "dhaka"));

but the http response that i get are:

Request URL:http://localhost/index.php/location/city
Request Method:POST
Status Code:200 OK

Date:Sun, 22 Jul 2012 10:27:32 GMT
Keep-Alive:timeout=5, max=100
Server:Apache/2.2.21 (Unix) mod_ssl/2.2.21 OpenSSL/0.9.8r DAV/2 PHP/5.3.6

The header
is missing in the response even after including
Access-Control-Expose-Headers: Access-Control-Allow-Origin
. My source of information about this header is from Mozilla Developer Website

Answer Source

It turns out, it worked for me only when i set the headers via the PHP syntax header() instead of the codeigniter syntax $CI->output->set_header(). That's sad.

Thanks to the first comment by @Yan at the Question of this topic

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download