Answers for "php how to set multiple headers for cors"

PHP
2

php cors multiple headers

// enter the origins you want allowed for cors to work
$_SESSION['allowed_origins'] = array('*', "site1.com", "site2.com");

// use this function to cycle through the list and enter these dynamically
function setAllowedHeadersAPI($array) {
    foreach ($_SESSION['allowed_origins'] as $origin) {
        header("Access-Control-Allow-Origin: $origin");
        header("Access-Control-Allow-Headers: $origin");
    }
}

// call function and pass the array through it
setAllowedHeadersAPI($_SESSION['allowed_origins']);
Posted by: Guest on August-24-2021
2

php how to set multiple headers for cors

// enter the origins you want allowed for cors to work
$_SESSION['allowed_origins'] = array('*', "site1.com", "site2.com");

// use this function to cycle through the list 
// and enter these dynamically
function setAllowedHeadersAPI($array) {
    foreach ($_SESSION['allowed_origins'] as $origin) {
        header("Access-Control-Allow-Origin: $origin");
        header("Access-Control-Allow-Headers: $origin");
    }
}

// call function and pass the array through it
setAllowedHeadersAPI($_SESSION['allowed_origins']);
Posted by: Guest on August-24-2021

Browse Popular Code Answers by Language