Home  >  Article  >  Backend Development  >  PHP Proxy

PHP Proxy

WBOY
WBOYOriginal
2016-07-25 09:09:393337browse
PHP 实现的网页代理
  1. if ( !isset($_REQUEST["url"]) ) exit;
  2. $u = $_REQUEST["url"];
  3. if (substr($u, -0, 7) != "http://") exit;
  4. echo file_get_contents( $u );
  5. /*
  6. function getPage($url, $referer, $timeout, $header=true){
  7. if(!isset($timeout)) $timeout=30;
  8. $curl = curl_init();
  9. if(strstr($referer,"://")){
  10. curl_setopt ($curl, CURLOPT_REFERER, $referer);
  11. }
  12. curl_setopt ($curl, CURLOPT_URL, $url);
  13. curl_setopt ($curl, CURLOPT_TIMEOUT, $timeout);
  14. curl_setopt ($curl, CURLOPT_USERAGENT, sprintf("Mozilla/%d.0",rand(4,5)));
  15. curl_setopt ($curl, CURLOPT_HEADER, (int)$header);
  16. curl_setopt ($curl, CURLOPT_RETURNTRANSFER, 1);
  17. curl_setopt ($curl, CURLOPT_SSL_VERIFYPEER, 0);
  18. $html = curl_exec ($curl);
  19. curl_close ($curl);
  20. return $html;
  21. }
  22. echo getPage( $u, "http://www.websitename.com", "20", false );
  23. */
  24. ?>
复制代码


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn