Cross domain issue in php

Use below code on the top of page with other domains URL.

<?php header(“Access-Control-Allow-Origin: http://sample.com”); ?>

If you want to add multiple cross domains add as follows:

<?php

$http_origin = $_SERVER[‘HTTP_ORIGIN’]; //To get current server  URL.
$urls=array(‘http://sample1.com’,’http://sample2.com’);  //Provide all other doamins as elements of array
if(in_array($http_origin,$urls)){
header(“Access-Control-Allow-Origin: $http_origin”);

}?>