how to allow cors through header in php

Solutions on MaxInterview for how to allow cors through header in php by the best coders in the world

showing results for - "how to allow cors through header in php"
Mads
11 Jan 2017
1 <?php
2 header("Access-Control-Allow-Origin: *");
Alessio
02 Apr 2019
1/**
2 *  An example CORS-compliant method.  It will allow any GET, POST, or OPTIONS requests from any
3 *  origin.
4 *
5 *  In a production environment, you probably want to be more restrictive, but this gives you
6 *  the general idea of what is involved.  For the nitty-gritty low-down, read:
7 *
8 *  - https://developer.mozilla.org/en/HTTP_access_control
9 *  - http://www.w3.org/TR/cors/
10 *
11 */
12function cors() {
13
14    // Allow from any origin
15    if (isset($_SERVER['HTTP_ORIGIN'])) {
16        // Decide if the origin in $_SERVER['HTTP_ORIGIN'] is one
17        // you want to allow, and if so:
18        header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
19        header('Access-Control-Allow-Credentials: true');
20        header('Access-Control-Max-Age: 86400');    // cache for 1 day
21    }
22
23    // Access-Control headers are received during OPTIONS requests
24    if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
25
26        if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD']))
27            // may also be using PUT, PATCH, HEAD etc
28            header("Access-Control-Allow-Methods: GET, POST, OPTIONS");         
29
30        if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']))
31            header("Access-Control-Allow-Headers: {$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}");
32
33        exit(0);
34    }
35
36    echo "You have CORS!";
37}
queries leading to this page
allow cors php headerphp allow cross origin domainraw php enable corsphp file allow cross origincrossorigin in a php serverdocument location origin phpphp allow cors from domainphp working solution for cors headers allow allphp send cors headerheader php access control allow origincors server to serverphp set up headers access ccontrolallow cors access control allow origin phpconfig cors php access controll allow origincors config php 22php get request origin 22header set access control allow origin php php php cors optionsaccess control origin header phpallow cors origin phpphp cors nlocl allow originadd access control allow origin header phpallow cors from remote server phphow to allow cors through header in phpphp syntax originhow to add corsadd allow cross origin cors phpstrict origin when cross origin phporigin method phpphp header access control allow originphp access control allow origin 3a 2aaccess control allow origin php examplephp header disable corsheader for cross origin in phpno cors php headersphp access origin headercross origin phpphp header access control allow originphp header for corsphp controller cors originadd cross origin header phpphp and corsphp access originallow origin header corshow to fix cors policy phpcors for phpaccess control allow origin php settingphp 8 allow cor headerscors response phpaccess control allow headers phpadd cors in phpaccess control allow origin phpphp post originphp cors headeradd cors to my php fileaccess control allow origin php headerphp cors requestaccess control allow origin in phpphp allow cross origin requestaccess control allow origin 2a php headerheader set access control allow originphp allow crossoriginset cross origin header phpphp script for corsallow cors in phpadditiing cors header in phpcors header phphow to set access control allow origincross origin allow all in phpenable cors phpallow origin phpphp header allow acess allow origincross origin request header with phpphp access control allow originapache php enable corsphp header cors allow allallow access control origin phpiframe allow cross origin header phphow to set cors headers in phpheader examples php allow cross originaccess controll allow origin phphttp origin phpphp header allow corsallow origin header phpuse php to get around corsphp allow cors to other sitesphp allow cross origin all domainheader allow origin phpaccess control allow origin header phpallow cross origin phpheader 28 22access control allow origin 3a 2a 22 meaning in php loginaccess control allow origin issue in phpenable cors for phpaccess control allow origin header in phpget origin phpphp allow same originphp add access control allow origin headerphp cross origin websitephp 27access control allow originphp header cross origin setget request origin in phphow to set access control allow originallow cors php serveradd access control allow origin javascript linkturn off cors check phpaccess control allow origin on phpcors policy phpphp corsturn off cors phphttp origin in php php cors not working php apachecors access control allow headers phpin which file do add corscors phpphp cors to a domainphp block cross origin requestsolve cors phphow to remove cors error in phpcors enable in phphow to solve cors error in phpcros enable cross siteenable cors php serverset cors phpphp cross policyheader allow access control allow origin phpcors allow phpallow all origins cors phphow to solve cors in phpallow headers cors phpwhere to add access control allow origin php access control allow originphp set cors headeraccess control allow origin 3a 2a phpphp access control allow origincors issue phpphp header allow originphp access control allow content typephp allow cors requestallo cors origin phpadd cors header to allow response in php apiphp cross origin handlingphp header originenabling ors on php serverenable all cors phpphp php corshow to change access control allow origin same in phpheader access control phpallow access control origin header php allphp allow cross origin codephp cors headrsadd php cors headers to api serverphp acces control allow origin headeradding cors in phpphp add header access control allow originallow access orgin header for phpenable cors in phpphp cors policyallow cross origin only from app phpphp cors allow all 3c 3f php header 28 27 27assecs control 29php 26 access control allow originaccess control allow origin in php headerphp origincors allow cross origin phpphp header code allow originphp cors policy no 27access control allow origin 27cross origin request phpheader 28 22access control allow origin 3a 2a 22 29 phpcors problem phpcors request allow in phpcors allow php originshow to allow cross origin requests in php filesallow access origin header phpphp allow cross originphp cross origin headerenable cors with phphow to add access control allow origin header in phpallow cross site phpphp cross origin allow allhow to allow cross origin in php codephp access control allow origin e2 80 99 not allowedcors policy error in phpphp cors allow origin for domainheader access control allow origin phpphp set header access control allow originphp set header corsenable cors pure phpphp redirect access control allow originphp adding access control allow origin corsphp cross origin functionallow cors php codeheader cors phpaccess control allow origin 2a phpallow cross origin php all headerphp cors pagephp get originaccess control allow origin 27 header phpwhere to set access control allow origin 3aaloow acees phpphp cross domain allowphp set corsphp header cors blocked by corscors allow origin phpaccess control origin phpcors issue when calling php scriptphp header croscross origin request in phpphp cors header addphp allow cors headerallow access cross origin phpcreate function to download file php with corshow to enable cors in phpphp allow control originhow to enable cross origin requests phpphp add header cross originphp allow cors originadd access control headers phpallow cors from the backend phpcors in phpenable corsproblemas con los cors phpallow origin cors phpaccept cors header phpajax access control allow origin php headercors in php filephp cors 27access control allow origin 27access control allow origin localhost phporigin phpallow access orgin all header for phphpw to add alloe cross origin header in phpphp cross domain policycors error phpcors access control allow origin phpphp set cross origin headeraccess origin allow code php filephp header allow cross originset cors header phpphp cors allowphp add cors headerphp allow origin headerphp access control allow origin localhostphp code allow cors accessphp allow access control originenable cors from phpaccess origin phpphp disable corsphp strict origin when cross originphp allow url fopencors php allowallow cors in php backendphp add access control allow origincors policy in phpphp enable corsphp allow access control allow headersfix cors php serversolve cors problem in phpallow origin in phpphp allow origin header htaccessset header access control allow origin phpphp access allow origin headerphp cross origin request allowenable cors in php filephp create rest api corsaccess control allow origin header phpphp cros originphp echo 22request origin 22allow cross broswer header phpaccess control allow origin 2a php headeaccess origin header phpcross origin request allow in phpaccess control allow origin php allphp get origin headerallow cors php allphp cross origina allow all headerphp allow corshow to disable cors in phpphp stop corsphp cors enablecors allow 1 domain phpcross origin header phpset header allow origin phpheader php allow originheader cross origin using phpallow cors phpactive cors in phpphp cross origin allphp header 28 22access control php request originhow to allow cross origin requests in phpget origin function phpadding cors header in phpcors javascriptwhat is cors in phpallow origin with phpphp set header allow originallow cross origin requests phpcors orgin phpenable cors header phpheader acep al origin phpcors allow origin php headerphp headers allow originresolve cors issue in phphostinger allow cors phpphp cross domain access control allow originphp get request originphp access control allow headersaccess allow origin header phpphp crossoriginphp set access control allow origin examplephp cors headersphp cross originhow to set php no corsphp 8 enable corsphp header cors allowunirest php 22cors 22cors snippetphp cors originheader allow acess origin in php add php cors headermeanig of cors headers in phpphp header request allow cross originallow control allow origin htmlhow to enable cors in phpcors php allow allallow cross origin in php headerphp header to allow cross originphp allow origin other sitestrict origin when cross origin in phpphp header disallow cross originallow post methosd for cross origin phpphp access control allow origin corscors origin phpcors headerphp access control allow origin to any acces control allow origin phpallow access origin phpheader cross origin phpset cross origin header to all phpphp header corsno 27access control allow origin 27 header phpiframe allow cross origin phpcors in php headerphp cors allow originphp allow all originsget request origin phpphp cross origin apachephp http originphp disable cross domain requestphp cors scriptenable cross origin phpphp allow access control allow origincors allow origin error phpphp allow cross origin requestsallow cors header phpphp allow crosphp header cross originaccess control allow origin https phpaccess control allow origin php header examplephp allow originaccess to xmlhttprequest at from origin in phpallow access control origin header phpset access control origin phpphp header access control allow origin 2aphp server originallow all origin cors phpheader allow cross origin phpaccess control allow origin 27 phpphp allow header originno cors phpphp to get around cors policyphp no 27access control allow origin 27 headerphp access control allow origin headerheader allow cross origin php 2aphp allow cross origin php selfphp include access has been blocked by cors policyphp origin headerphp enable cross origincors on phpphp enable cors headersset cors in phpaccess control allow origin php headerhow to allow cors phphtaccess cross origin allow phpphp set access control allow origincross origin in phpallow cross origin in php access control allow origin phpaccess control allow origin phpaccess control allow origin php list urlscross origin on php siteenable access control allow origin phpallow cors cors allow xml php headersconfig 2fcors phphow to allow cors through header in php