/lbar/proxy.php

https://github.com/nbcutech/o3drupal · PHP · 66 lines · 35 code · 6 blank · 25 comment · 5 complexity · 28a82f548d57a926a3c14d57d37ad285 MD5 · raw file

  1. <?php
  2. // FILE: proxy.php
  3. //
  4. // LAST MODIFIED: 2006-03-23
  5. //
  6. // AUTHOR: Troy Wolf <troy@troywolf.com>
  7. //
  8. // DESCRIPTION: Allow scripts to request content they otherwise may not be
  9. // able to. For example, AJAX (XmlHttpRequest) requests from a
  10. // client script are only allowed to make requests to the same
  11. // host that the script is served from. This is to prevent
  12. // "cross-domain" scripting. With proxy.php, the javascript
  13. // client can pass the requested URL in and get back the
  14. // response from the external server.
  15. //
  16. // USAGE: "proxy_url" required parameter. For example:
  17. // http://www.mydomain.com/proxy.php?proxy_url=http://www.yahoo.com
  18. //
  19. // proxy.php requires Troy's class_http. http://www.troywolf.com/articles
  20. // Alter the path according to your environment.
  21. require_once("class_http.php");
  22. $proxy_url = isset($_GET['proxy_url'])?$_GET['proxy_url']:false;
  23. if (!$proxy_url) {
  24. header("HTTP/1.0 400 Bad Request");
  25. echo "proxy.php failed because proxy_url parameter is missing";
  26. exit();
  27. }
  28. // Instantiate the http object used to make the web requests.
  29. // More info about this object at www.troywolf.com/articles
  30. if (!$h = new http()) {
  31. header("HTTP/1.0 501 Script Error");
  32. echo "proxy.php failed trying to initialize the http object";
  33. exit();
  34. }
  35. $h->url = $proxy_url;
  36. //if (!$h->fetch($h->url)) {
  37. $verb = $_SERVER["REQUEST_METHOD"];
  38. if ($verb == "POST"){
  39. $h->postvars = array( @file_get_contents('php://input') );//$_POST;
  40. }
  41. if(!$h->fetch($h->url, 0, null, null, null,$verb)) {
  42. header("HTTP/1.0 501 Script Error");
  43. echo "proxy.php had an error attempting to query the url";
  44. exit();
  45. }
  46. // Forward the headers to the client.
  47. $ary_headers = split("\n", $h->header);
  48. foreach($ary_headers as $hdr) { header($hdr); }
  49. // Send the response body to the client.
  50. echo $h->body;
  51. ob_start();
  52. print_r($_SERVER);
  53. print "\n";
  54. $text = ob_get_contents();
  55. ob_end_flush();
  56. $text .= @file_get_contents('php://input');
  57. $text .= $h->url."\n";
  58. $text .= $h->body."\n\n";
  59. #file_put_contents("log.txt",$text."\n\n", FILE_APPEND);
  60. ?>