php how to set multiple headers for cors

Solutions on MaxInterview for php how to set multiple headers for cors by the best coders in the world

showing results for - "php how to set multiple headers for cors"
Mía
17 Jan 2019
1// enter the origins you want allowed for cors to work
2$_SESSION['allowed_origins'] = array('*', "site1.com", "site2.com");
3
4// use this function to cycle through the list and enter these dynamically
5function setAllowedHeadersAPI($array) {
6    foreach ($_SESSION['allowed_origins'] as $origin) {
7        header("Access-Control-Allow-Origin: $origin");
8        header("Access-Control-Allow-Headers: $origin");
9    }
10}
11
12// call function and pass the array through it
13setAllowedHeadersAPI($_SESSION['allowed_origins']);
Mylan
03 May 2018
1// enter the origins you want allowed for cors to work
2$_SESSION['allowed_origins'] = array('*', "site1.com", "site2.com");
3
4// use this function to cycle through the list 
5// and enter these dynamically
6function setAllowedHeadersAPI($array) {
7    foreach ($_SESSION['allowed_origins'] as $origin) {
8        header("Access-Control-Allow-Origin: $origin");
9        header("Access-Control-Allow-Headers: $origin");
10    }
11}
12
13// call function and pass the array through it
14setAllowedHeadersAPI($_SESSION['allowed_origins']);