Created
April 22, 2019 09:51
-
-
Save laocoi/54143a5d1cdb72d159997042b165fce4 to your computer and use it in GitHub Desktop.
The following snippet should give you a quick overview about the required HTTP headers to set for CORS to work.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$allowedOrigins = array( | |
'(http(s)://)?(www\.)?my\-domain\.com' | |
); | |
if (isset($_SERVER['HTTP_ORIGIN']) && $_SERVER['HTTP_ORIGIN'] != '') { | |
foreach ($allowedOrigins as $allowedOrigin) { | |
if (preg_match('#' . $allowedOrigin . '#', $_SERVER['HTTP_ORIGIN'])) { | |
header('Access-Control-Allow-Origin: ' . $_SERVER['HTTP_ORIGIN']); | |
header('Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS'); | |
header('Access-Control-Max-Age: 1000'); | |
header('Access-Control-Allow-Headers: Content-Type, Authorization, X-Requested-With'); | |
break; | |
} | |
} | |
} | |
Source: https://www.kerstner.at/2015/02/enabling-cross-origin-resource-sharing-cors-for-php/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment