function urlfopen($url, $limit = 0, $post = '', $cookie = '', $bysocket = FALSE , $ip = ' ', $timeout = 15, $block = TRUE, $encodetype = 'URLENCODE') {- $return = '';
- $matches = parse_url($url);
- $host = $matches['host'];
- $path = $matches['path'] ? $matches['path'].(isset($matches['query']) ? '?'.$matches['query'] : '') : '/';
- $port = !empty($matches[ 'ポート']) ? $matches['port'] : 80;
-
- if($post) {
- $out = "POST $path HTTP/1.0rn";
- $out .= "Accept: */*rn";
- $out . = "Accept-Language: zh-cnrn";
- $boundary = $encodetype == 'URLENCODE' ? '' : ';'.substr($post, 0, トリム(strpos($post, "n")));
- $out .= $encodetype == 'URLENCODE' ? "Content-Type: application/x-www-form-urlencodedrn" : "Content-Type: multipart/form-data$boundaryrn";
- $out .= "ユーザーエージェント: $_SERVER[HTTP_USER_AGENT]rn";
- $ out .= "ホスト: $hostrn";
- $out .= 'Content-Length: '.strlen($post)."rn";
- $out .= "接続: Closern";
- $out .= "キャッシュ-Control: no-cachern";
- $out .= "Cookie: $cookiernrn";
- $out .= $post;
- } else {
- $out = "GET $path HTTP/1.0rn";
- $out . = "受け入れ: */*rn";
- $out .= "受け入れ言語: zh-cnrn";
- $out .= "ユーザーエージェント: $_SERVER[HTTP_USER_AGENT]rn";
- $out .= "ホスト: $hostrn";
- $out .= "リファラー: rn";
- $out .= "接続: Closern";
- $out .= "Cookie: $cookiernrn";
- }
- $fp = @fsockopen(($ ip ? $ip : $host), $port, $errno, $errstr, $timeout);
- if(!$fp) {
- return '';
- } else {
- stream_set_blocking($fp, $block);
- stream_set_timeout($fp, $timeout);
- @fwrite($fp, $out);
- $status = stream_get_meta_data($fp);
- if(!$status['timed_out']) {
- while (!feof($) fp)) {
- if(($header = @fgets($fp)) && ($header == "rn" || $header == "n")) {
- Break;
- }
- }
-
- $stop = false;
- while(!feof($fp) && !$stop) {
- $data = fread($fp, ($制限 == 0 || $limit > 8192 : $limit));
- $return .= $data;
- if($limit) {
- $limit -= strlen($data);
- $stop = $ limit }
- }
- }
- @fclose($fp);
- return $return;
- }
- }
-
复制代
|