Skip to content

Instantly share code, notes, and snippets.

@jayshields
Created August 11, 2016 15:13
Show Gist options
  • Save jayshields/912df25a8e66f42d42eb3b333d2b2120 to your computer and use it in GitHub Desktop.
Save jayshields/912df25a8e66f42d42eb3b333d2b2120 to your computer and use it in GitHub Desktop.
Access-Control-Allow-Origin whitelist for Silex
$app->after(function(Request $request, Response $response){
$access_whitelist = array('https://domain1.com', 'https://domain2.com', 'https://domain3.com');
if(in_array($_SERVER['HTTP_ORIGIN'], $access_whitelist))
$response->headers->set('Access-Control-Allow-Origin', $_SERVER['HTTP_ORIGIN']);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment