header('Access-Control-Allow-Origin: *'); Not allowing CORS request

cors, php

Solution

It doesn't look there is anything wrong with the code that sets the header, but you may want to check if the header is actually being set. Use `curl -i http://yourapp` to check the response headers being sent to debug it. Alternatively, you can use the network tab in Google Chrome's web inspector, or the Network tool in Firefox's Web Developer tools.

Problem

I have a PHP file which generates a JSON document. I've set the `header` as follows but am still getting an error. ``` header('Access-Control-Allow-Origin: *'); header('Content-Type: application/json'); ``` Error message: `No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://mysubdomain.mydomain.com' is therefore not allowed access.` I've tried explictly allowing mysubdomain.mydomain.com using ``` header('Access-Control-Allow-Origin: https://mysubdomain.mydomain.com'); ``` But I still get the error.

Original source