php cors header multiple domains

Solutions on MaxInterview for php cors header multiple domains by the best coders in the world

showing results for - "php cors header multiple domains"
Liana
22 Oct 2018
1//Function to be called first in php file.
2function CORS_HEADERS_HANDLER(){
3  if (isset($_SERVER['HTTP_ORIGIN'])){
4    switch($_SERVER['HTTP_ORIGIN']){
5        //Handle an IP address and Port
6      case 'http://1.2.3.4:4200':
7        header('Access-Control-Allow-Origin: http://1.2.3.4:4200');
8        break;
9        //Handle an Website Domain (using https)
10      case 'https://www.someSite.com':
11        header('Access-Control-Allow-Origin: https://www.someSite.com');
12        break;
13        //Handle an Website Domain (using http)
14      case 'http://www.someSite.com':
15        header('Access-Control-Allow-Origin: http://www.someSite.com');
16        break;
17        //Catch if someone's site is actually the reject being cheeky
18      case 'https://not.you':
19        header('Access-Control-Allow-Origin: https://nice.try');
20        break;
21        //Handle a rejection passing something that is not the request origin.
22      default:
23        header('Access-Control-Allow-Origin: https://not.you');
24        break;
25    }
26  }else{
27    header('Access-Control-Allow-Origin: https://not.you');
28  }
29  header('Access-Control-Allow-Methods: GET, POST, PATCH, PUT, DELETE, OPTIONS');
30  header('Access-Control-Allow-Headers: Origin, Content-Type, X-Auth-Token');
31  header('Access-Control-Allow-Credentials: true');
32  header('Content-Type: application/json; charset=utf-8');
33  header("Cache-Control: public,max-age=3600");
34  //if its an options request you don't need to proceed past CORS request.
35  if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
36    die();
37  }
38}
queries leading to this page
cors with origins add multiple domains startupaccess control origin from multiple domain phpaccess control allow origin multipleset multiple access control allow origincors origin with list domaincors with origins add multiple domainscors access control allow origin multiple domainsheader set access control allow origin multiple domainsaccess control allow origin header multiple domains phpphp cors multiple headershow to add multi access control allow origin to headercors multiple hostshow to allow multiple domains to cors phpaccess control allow origin more valuescors filter allow multiple originsphp cors headeraccess control allow origin multiple domains phpphp cors policy no access control allow origin multiple domainsphp header alow multi orinigrequest allow origin multiplephp allow cors for two domainsset multiple domains for corscors multiple originsaccess control allow origin set 2 originsphp cors header multiple domainscors allow two domainsaccess control allow origin multiple subdomain domainsaccess control allow origin php multiple domainscors add multiple domainscors allow multiple originsaccess control allow origin header multiple domainsaccess control allow origin multiple domainsallow multiple origins corsheader set access control allow origin multiple valueaccess control allow origin multiple domains apacheset header 28 22access control allow origin multiple siteaccess control allow origin multiple domainsmultiple origin corsphp allow multi cors originallow headers cors from 2 domain phptwo domains to corsheader always set access control allow origin put multiple domainsphp cors header multiple domains