dfopen 시뮬레이션 html 요청

2712 단어 htmlcacheFP
function dfopen($url, $limit = 0, $post = '', $cookie = '', $bysocket = FALSE, $ip = '', $timeout = 15, $block = TRUE)
{
	$return = '';
	$uri = parse_url($url);
	$host = $uri['host'];
	$path = $uri['path'] ? $uri['path'].($uri['query'] ? '?'.$uri['query'] : '') : '/';
	$port = !empty($uri['port']) ? $uri['port'] : 80;

	if($post) {
		$out = "POST $path HTTP/1.0\r
"; $out .= "Accept: */*\r
"; //$out .= "Referer: $boardurl\r
"; $out .= "Accept-Language: zh-cn\r
"; $out .= "Content-Type: application/x-www-form-urlencoded\r
"; $out .= "User-Agent: $_SERVER[HTTP_USER_AGENT]\r
"; $out .= "Host: $host\r
"; $out .= 'Content-Length: '.strlen($post)."\r
"; $out .= "Connection: Close\r
"; $out .= "Cache-Control: no-cache\r
"; $out .= "Cookie: $cookie\r
\r
"; $out .= $post; } else { $out = "GET $path HTTP/1.0\r
"; $out .= "Accept: */*\r
"; //$out .= "Referer: $boardurl\r
"; $out .= "Accept-Language: zh-cn\r
"; $out .= "User-Agent: $_SERVER[HTTP_USER_AGENT]\r
"; $out .= "Host: $host\r
"; $out .= "Connection: Close\r
"; $out .= "Cookie: $cookie\r
\r
"; } $fp = @fsockopen(($ip ? $ip : $host), $port, $errno, $errstr, $timeout); if(!$fp) { return '';//note $errstr : $errno \r
} else { // / ,$block==true stream_set_blocking($fp, $block); // stream_set_timeout($fp, $timeout); @fwrite($fp, $out); // / $status = stream_get_meta_data($fp); //timed_out fread() fgets() TRUE, if(!$status['timed_out']) { while (!feof($fp)) { if(($header = @fgets($fp)) && ($header == "\r
" || $header == "
")) { break; } } $stop = false; // while(!feof($fp) && !$stop) { // =0 8192 =》8192 else =》limit $data = fread($fp, ($limit == 0 || $limit > 8192 ? 8192 : $limit)); $return .= $data; if($limit) { $limit -= strlen($data); $stop = $limit <= 0; } } } @fclose($fp); return $return; } }

좋은 웹페이지 즐겨찾기