php cors error

Solutions on MaxInterview for php cors error by the best coders in the world

showing results for - "php cors error"
Damián
02 Apr 2018
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 *  - https://fetch.spec.whatwg.org/#http-cors-protocol
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}
38
Horace
10 Nov 2016
1Access-Control-Allow-Headers does not allow * as accepted value, see the Mozilla Documentation here.
2
3Instead of the asterisk, you should send the accepted headers (first X-Requested-With as the error says).
queries leading to this page
cors with phpphp http corstus php corscors php allowphp allow headerwhat is cors in phpphpdisable corscors error in phphow to bypass cors phphow to enable cors in php iphp cors headerstrict origin when cross origin phpcors origin phpaccess control allow headers phpphp access control allow methodsphp cros originphp 5 6 cors errorall all cors in phpcors php headerssphp haders corsphp cors problemcors in phphow to allow cors phpphp get cors errorphp cors whitelistaccept url php crosalloworigin cors https in phpphp cors header errorcors phpcors php headererro cors phpenable cors header phpphp returning corsphp add header corswhat is cors phpphp 8 enable corsallow cors php codephp cors funchttps php cors policyhow to solve cors error in phpphp cli server allow corsallow cors phpphp server allow corscors php localhostcors php headersenable the cors phpenabling cors support phpx cors phpwhere to put cors in phpphp php corsphp access control allow content typephp cors not working php apachephp cors originphp cors allowsetup cors policy phpphp enable corsphp allow corshow to enable cors in phphow to handle php cors 3fphp header for corscors php urlscors checking phpphp set header no crossphp header access strictcors backend in phphow to enable cors on php filerow php allow corshow to get around cors error with phpset cors in phpenable cors pure phpcors phpphp localhost cors how to activate cors in phpphp cors headershow to enable cors in php apicors origin error phpphp local server corsenable cors in phpset cors allow origin url pgpphp cors releasecors error phpcors in constructor phpsolution for cors error phpfix cors in phpallow cors in phpallow method phpcors error in php apiphp disable corsphp and corslocal php allow corsphp set cors headerserror cors php in localadding cors support phpphp cors policycors php enablecors problem in phpalors cors phpcors header phpapache cors phpphp set header corscors enable in phpmake php corswhen i use cors in phpphp cors installhow to solve cors in phpcors server phphow to enable cors phpallow cors in php heaersadd cors in phpaccept cors header phpcors headers phpphp cors options requestcors in localhost phpcors from a php servercors block phpphp cors issuephp force corsphp cors errorcors php fixphp cors requestphp set cors headercors issue 2b php php activate http originhow to allow cors in phpinclude cors header phpphp php cors optionshow to enable cors in phpphp cors exampleset cors header phpenable cors phpphp cors packagephp add cors headercors in php api allphp cors error 3fapi php corsphp corsphp set corswhat is cors problemecors orgin phpcors access control phpphp cors error