CodeIgniter Forums
Enable CORS in CI 3.0 - Printable Version

+- CodeIgniter Forums (
+-- Forum: Using CodeIgniter (
+--- Forum: General Help (
+--- Thread: Enable CORS in CI 3.0 (/showthread.php?tid=64571)

Enable CORS in CI 3.0 - sammyci - 03-05-2016

In my non-CI app, the following does disable CORS (for trial apps):

$request_headers = apache_request_headers();
$http_origin = $request_headers['Origin'];
header("Access-Control-Allow-Origin: $http_origin");

For CI, it failed no matter where I put it in my controller.

header('Access-Control-Allow-Origin: *');
header("Access-Control-Allow-Headers: X-API-KEY, Origin, X-Requested-With, Content-Type, Accept, Access-Control-Request-Method");
header("Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT, DELETE");
if($method == "OPTIONS") {

placed in many advised places failed too. Am I missing somethg?

RE: Enable CORS in CI 3.0 - InsiteFX - 03-05-2016

Try placing it the html document, you can create a header view and load it.

RE: Enable CORS in CI 3.0 - albertleao - 03-05-2016

I have my header code as a hook

RE: Enable CORS in CI 3.0 - sammyci - 07-11-2016

I think not replying is better than very generic replies which are meant, I think, to confuse than to solve.

RE: Enable CORS in CI 3.0 - ismaelirc - 09-02-2016

If anyone came here with the same problem, my solution was:

I was using the csrf_token protection and because of this I had to inform the url that receive the POST in $config['csrf_exclude_uris'] and works fine Wink