Skip to content

Instantly share code, notes, and snippets.

@mathewka
Created April 15, 2014 05:40
Show Gist options
  • Select an option

  • Save mathewka/10705034 to your computer and use it in GitHub Desktop.

Select an option

Save mathewka/10705034 to your computer and use it in GitHub Desktop.
Allow cross domain access
$method = $_SERVER['REQUEST_METHOD'];
if (isset($_SERVER['HTTP_ORIGIN'])) {
drupal_add_http_header('Access-Control-Allow-Origin', $_SERVER['HTTP_ORIGIN']);
}
if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS'])) {
drupal_add_http_header('Access-Control-Allow-Headers', $_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']);
}
if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD'])) {
drupal_add_http_header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');
}
if ($method == 'OPTIONS') {
exit;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment