当前位置:Gxlcms > PHP教程 > PHP实现的网页代理

PHP实现的网页代理

时间:2021-07-01 10:21:17 帮助过:5人阅读

  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

人气教程排行