Skip to content

Instantly share code, notes, and snippets.

@Alotor
Last active August 29, 2015 14:11
Show Gist options
  • Save Alotor/fe409f0666d8a0243807 to your computer and use it in GitHub Desktop.
Save Alotor/fe409f0666d8a0243807 to your computer and use it in GitHub Desktop.
PHP Script to enable CORS for GET methods
<?php
$ch = curl_init();
if (strcmp($_SERVER["REQUEST_METHOD"], "GET") == 0) {
curl_setopt($ch, CURLOPT_URL, $_REQUEST["url"]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec ($ch);
$contentType = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
curl_close ($ch);
header("Content-Type: " . $contentType);
header("Access-Control-Allow-Origin: *");
echo($server_output);
} else {
http_response_code(400);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment