Cross Origin Request Blocked CORS header Access-Control-Allow-Origin missing

Cross-Origin Request Blocked error occurs on when a request sent from a domain(Domain-A) to an another domain(Domain-B).
Domian-B need access authorisation to allow Domian-A. So Cross-Origin Resource Sharing (CORS) header is added at the top of Domain-B in the requesting URL.

For single Domain CORS allow,

#Added your domain to allow access..
header('Access-Control-Allow-Origin: http://www.site.com');
#Allowing methods of request are added by comma seperated..
header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS');
header('Access-Control-Allow-Headers: Content-Type, Authorization, X-Requested-With');
For multiple Domain CORS allow,
$site_origin = $_SERVER['HTTP_ORIGIN'];
if ($site_origin == "http://www.site1.com" || $site_origin == "http://www.site2.com" || $site_origin == "http://www.site3.com")
{  
    header("Access-Control-Allow-Origin: $site_origin");
}
#Allowing methods of request are added by comma seperated..
header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS');
header('Access-Control-Allow-Headers: Content-Type, Authorization, X-Requested-With');
For Any Domain CORS allow,
#Added your domain to allow access..
header('Access-Control-Allow-Origin: *');
#Allowing methods of request are added by comma seperated..
header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS');
header('Access-Control-Allow-Headers: Content-Type, Authorization, X-Requested-With');

 

 

PHP CORS Posted on 2016-06-16 07:38:06