Skip to content

Instantly share code, notes, and snippets.

@marcusasplund
Created December 1, 2015 20:21
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save marcusasplund/0a67562ec775c461a53b to your computer and use it in GitHub Desktop.
Save marcusasplund/0a67562ec775c461a53b to your computer and use it in GitHub Desktop.
// a really, really simple proxy to request
// non-CORS enabled webservices
// Drop this script on your server and prepend
// the url you want to access like e.g.
// $.getJSON("http://pathtouyourserver.com/folderwiththisscript/corsproxy.php?url=http://theapiwithoutcors.com").success(....
//
// You find a more sophisticated one here: http://benalman.com/projects/php-simple-proxy/
<?php
$url = $_GET['url'];
$content = file_get_contents($url);
header('Access-Control-Allow-Origin: *');
echo $content;
?>
@posixpascal
Copy link

Just a quick headsup for anyone using this in production, this is vulnerable to lookup attacks (e.g. corsproxy.php?url=../../../etc/passwd).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment