2

i have a problem in my site.

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the 
remote resource at http://example.com/index.php.
(Reason: CORS header 'Access-Control-Allow-Origin' missing).

when i search about this error, the reason was sending request to an external domain. but it's not my problem reason, because all of my request is right to the source domain.

my domain is http://example.com and all requests are to the http://example.com/index.php.

*UPDATE:

This was just because of i was in use some un-handled headers in my request, so when the preflight Option response received, there was no access allow to that header from server, so this error happened.

  • 1
    Keep in mind that CORS is *very strict*! Meaning that `http://example.com` and `http://www.example.com` are *not* the same domains unless *www* is defined as a CNAME in your DNS records. – icecub Sep 05 '16 at 04:54

2 Answers2

-2
Access-Control-Allow-Origin: *

this might help put it in the header and if u want more than you can check.. here https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS

Vivek Singh
  • 2,453
  • 1
  • 14
  • 27
  • You seriously want him to open his domain up to any resource?! Talking about security risks.. – icecub Sep 05 '16 at 05:00
-2

Try adding below code in API controller constructor, it works for me.

ERROR : Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at [the url]

This can be fixed by moving the resource to the same domain or enabling CORS.

header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Methods: PUT, GET, POST");
header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept");
Paul Roub
  • 36,322
  • 27
  • 84
  • 93
  • 1
    Basicly what you're doing here is this: My firewall is blocking my game on port 2300. Lets remove the firewall completely to solve the issue. – icecub Sep 05 '16 at 05:15
  • @icecub can we give access to a particular IP? for example header("Access-Control-Allow-Origin: 172.123.23.23"); assuming this my server's IP where application is hosted? – Talha Malik Sep 07 '16 at 06:56