Created
February 18, 2019 22:05
-
-
Save pulketo/e1458a7353271f4e43ba9414a0f334a5 to your computer and use it in GitHub Desktop.
CORS php
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
// array holding allowed Origin domains | |
$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; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment