CORS in PHP

Kod:

if (isset($_SERVER["HTTP_ORIGIN"])) {
  header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
}

header("Access-Control-Allow-Credentials: true");

if (isset($_SERVER["HTTP_ACCESS_CONTROL_REQUEST_HEADERS"])) {
  header("Access-Control-Allow-Headers: {$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}");
}

if (isset($_SERVER["HTTP_ACCESS_CONTROL_REQUEST_METHOD"])) {
  header("Access-Control-Allow-Methods: {$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD']}");
}

A jak to vyzkouset:

curl -si -H "Origin: 111" -H "Access-Control-Request-Headers: 222" -H "Access-Control-Request-Method: 333" http://xxxxxx

a v hlavickach dostanu:

Access-Control-Allow-Origin: 111
Access-Control-Allow-Credentials: true
Access-Control-Allow-Headers: 222
Access-Control-Allow-Methods: 333
dev
Není-li uvedeno jinak, obsah této stránky je pod licencí Creative Commons Attribution-ShareAlike 3.0 License