Last active
August 29, 2015 14:11
-
-
Save Alotor/fe409f0666d8a0243807 to your computer and use it in GitHub Desktop.
PHP Script to enable CORS for GET methods
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 | |
$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