欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

PHP 实现的网页代理

程序员文章站 2022-05-30 16:46:18
...
  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. ?>
复制代码

PHP