Created
November 22, 2011 04:53
-
-
Save therealklanni/1384925 to your computer and use it in GitHub Desktop.
Stupidly simple PHP proxy
This file contains hidden or 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 | |
// Stupidly simple PHP proxy for AJAX (HTTP GET) requests. Written by Kevin Lanni. | |
$dest = ''; // Set to the remote script URL (i.e. http://remotehost.com/some.php) | |
$a = array(); | |
foreach ($_GET as $k=>$v) { | |
$a[] = "{$k}={$v}"; | |
} | |
echo file_get_contents($dest.'?'.implode('&',$a)); | |
?> |
....or even simpler:
<?php
$dest = '';
echo file_get_contents($dest.'?'.http_build_query($_GET));
?>
;-)
...
<?php
$dest = '';
echo file_get_contents($dest.'?'.$_SERVER['QUERY_STRING']);
?>
Thanks, those are some pretty good ideas. Feel free to fork this gist :)
I'll try your methods out when I have a little time to play around and then update my gist.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Oh man. I just had a really hard time because of your proxy. I was looking for the bug everywhere in my Code until I finally remembered that I use your proxy. ...and there it was!
I like the proxy because it's "stupidly simple" and that's sometimes all you need.
However, I think you made it to simple.
The $_GET variable is urldecoded and you're using this encoded Version for the query. You should, however, use the encoded Version of the parameter because otherwise it's not possible to use your proxy for encoded urls. :-/
This will fix it: