Skip to content

PHP code snippet – How to set multiple headers for cors?

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

// 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
See also  How to check number format exception in Java?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.