Welcome Guest, Not a member yet? Register   Sign In
Enable CORS in CI 3.0

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?

Try placing it the html document, you can create a header view and load it.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )

I have my header code as a hook
Codeigniter is simply one of the tools you need to learn to be a successful developer. Always add more tools to your coding arsenal!

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

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

Theme © iAndrew 2016 - Forum software by © MyBB