Posted By

spraitas on 06/18/09


Tagged

include proxy


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

wirenaught


PHP url proxy


 / Published in: PHP
 

  1. <?php
  2. // PHP Proxy
  3. // Responds to both HTTP GET and POST requests
  4. //
  5. // Author: Abdul Qabiz
  6. // March 31st, 2006
  7. //
  8.  
  9. // Get the url of to be proxied
  10. // Is it a POST or a GET?
  11. $url = ($_POST['url']) ? $_POST['url'] : $_GET['url'];
  12. $headers = ($_POST['headers']) ? $_POST['headers'] : $_GET['headers'];
  13. $mimeType =($_POST['mimeType']) ? $_POST['mimeType'] : $_GET['mimeType'];
  14.  
  15.  
  16. //Start the Curl session
  17. $session = curl_init($url);
  18.  
  19. // If it's a POST, put the POST data in the body
  20. if ($_POST['url']) {
  21. $postvars = '';
  22. while ($element = current($_POST)) {
  23. $postvars .= key($_POST).'='.$element.'&';
  24. next($_POST);
  25. }
  26. curl_setopt ($session, CURLOPT_POST, true);
  27. curl_setopt ($session, CURLOPT_POSTFIELDS, $postvars);
  28. }
  29.  
  30. // Don't return HTTP headers. Do return the contents of the call
  31. curl_setopt($session, CURLOPT_HEADER, ($headers == "true") ? true : false);
  32.  
  33. curl_setopt($session, CURLOPT_FOLLOWLOCATION, true);
  34. //curl_setopt($ch, CURLOPT_TIMEOUT, 4);
  35. curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
  36.  
  37. // Make the call
  38. $response = curl_exec($session);
  39.  
  40. if ($mimeType != "")
  41. {
  42. // The web service returns XML. Set the Content-Type appropriately
  43. header("Content-Type: ".$mimeType);
  44. }
  45.  
  46. echo $response;
  47.  
  48. curl_close($session);
  49.  
  50. ?>

Report this snippet  

You need to login to post a comment.