/lbar/proxy.php
https://github.com/nbcutech/o3drupal · PHP · 66 lines · 35 code · 6 blank · 25 comment · 5 complexity · 28a82f548d57a926a3c14d57d37ad285 MD5 · raw file
- <?php
- // FILE: proxy.php
- //
- // LAST MODIFIED: 2006-03-23
- //
- // AUTHOR: Troy Wolf <troy@troywolf.com>
- //
- // DESCRIPTION: Allow scripts to request content they otherwise may not be
- // able to. For example, AJAX (XmlHttpRequest) requests from a
- // client script are only allowed to make requests to the same
- // host that the script is served from. This is to prevent
- // "cross-domain" scripting. With proxy.php, the javascript
- // client can pass the requested URL in and get back the
- // response from the external server.
- //
- // USAGE: "proxy_url" required parameter. For example:
- // http://www.mydomain.com/proxy.php?proxy_url=http://www.yahoo.com
- //
- // proxy.php requires Troy's class_http. http://www.troywolf.com/articles
- // Alter the path according to your environment.
- require_once("class_http.php");
- $proxy_url = isset($_GET['proxy_url'])?$_GET['proxy_url']:false;
- if (!$proxy_url) {
- header("HTTP/1.0 400 Bad Request");
- echo "proxy.php failed because proxy_url parameter is missing";
- exit();
- }
- // Instantiate the http object used to make the web requests.
- // More info about this object at www.troywolf.com/articles
- if (!$h = new http()) {
- header("HTTP/1.0 501 Script Error");
- echo "proxy.php failed trying to initialize the http object";
- exit();
- }
- $h->url = $proxy_url;
- //if (!$h->fetch($h->url)) {
- $verb = $_SERVER["REQUEST_METHOD"];
- if ($verb == "POST"){
- $h->postvars = array( @file_get_contents('php://input') );//$_POST;
- }
- if(!$h->fetch($h->url, 0, null, null, null,$verb)) {
- header("HTTP/1.0 501 Script Error");
- echo "proxy.php had an error attempting to query the url";
- exit();
- }
- // Forward the headers to the client.
- $ary_headers = split("\n", $h->header);
- foreach($ary_headers as $hdr) { header($hdr); }
- // Send the response body to the client.
- echo $h->body;
- ob_start();
- print_r($_SERVER);
- print "\n";
- $text = ob_get_contents();
- ob_end_flush();
- $text .= @file_get_contents('php://input');
- $text .= $h->url."\n";
- $text .= $h->body."\n\n";
- #file_put_contents("log.txt",$text."\n\n", FILE_APPEND);
- ?>