Created
August 27, 2020 14:03
-
-
Save wilcorrea/67f49b809b32d6e100c1cd05a8d95a4d to your computer and use it in GitHub Desktop.
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
<?php | |
# allow all methods | |
header('Access-Control-Allow-Methods: POST, GET, PUT, PATCH, DELETE, OPTIONS'); | |
# allow some headers | |
header('Access-Control-Allow-Headers: Authorization, Bearer, Device, Origin, Accept, Content-Type'); | |
# allow expose some headers | |
header('Access-Control-Expose-Headers: Authorization, Bearer, Device'); | |
# get the request method | |
$method = $_SERVER['REQUEST_METHOD'] ?? null; | |
# check if method is OPTIONS... | |
if (strtoupper($method) === 'OPTIONS') { | |
# ...detects if there is an origin | |
$origin = $_SERVER['HTTP_ORIGIN'] ?? '*'; | |
# allow origin | |
header("Access-Control-Allow-Origin: {$origin}"); | |
# allow credentials (optional) | |
header('Access-Control-Allow-Credentials: true'); | |
exit(1); | |
} | |
// your code here... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment