Skip to content

Instantly share code, notes, and snippets.

@josfaber
Last active January 29, 2022 11:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save josfaber/1f6b974ea3c87bf53755b06210453b71 to your computer and use it in GitHub Desktop.
Save josfaber/1f6b974ea3c87bf53755b06210453b71 to your computer and use it in GitHub Desktop.
Allow specific domains and url's | Access-Control-Allow-Origin in PHP
$origin = $_SERVER['HTTP_ORIGIN'];
$allowed_domains = [
'http://localhost',
'http://localhost:8080',
'http://localhost:8081',
'https://example.com',
'https://test.example.com',
'http://example.net',
];
if (in_array($origin, $allowed_domains)) {
header('Access-Control-Allow-Origin: ' . $origin);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment