Posted By

chrisaiv on 07/20/11


Tagged

php proxy


Versions (?)

PHP: PHP Proxy


 / Published in: PHP
 

Sometimes you need a PHP script that will serve as a page proxy. Here it is!

  1. <?php
  2. if ( !isset($_REQUEST["url"]) ) exit;
  3.  
  4. $u = $_REQUEST["url"];
  5. if (substr($u, -0, 7) != "http://") exit;
  6.  
  7.  
  8. /*
  9. function getPage($url, $referer, $timeout, $header=true){
  10. if(!isset($timeout)) $timeout=30;
  11. $curl = curl_init();
  12. if(strstr($referer,"://")){
  13. curl_setopt ($curl, CURLOPT_REFERER, $referer);
  14. }
  15. curl_setopt ($curl, CURLOPT_URL, $url);
  16. curl_setopt ($curl, CURLOPT_TIMEOUT, $timeout);
  17. curl_setopt ($curl, CURLOPT_USERAGENT, sprintf("Mozilla/%d.0",rand(4,5)));
  18. curl_setopt ($curl, CURLOPT_HEADER, (int)$header);
  19. curl_setopt ($curl, CURLOPT_RETURNTRANSFER, 1);
  20. curl_setopt ($curl, CURLOPT_SSL_VERIFYPEER, 0);
  21. $html = curl_exec ($curl);
  22. curl_close ($curl);
  23. return $html;
  24. }
  25.  
  26. echo getPage( $u, "http://www.websitename.com", "20", false );
  27. */
  28. ?>

Report this snippet  

You need to login to post a comment.