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.0rn";
$out .= "Accept: */*rn";
$out . = "Accept-Language: zh-cnrn";
$out .= "Content-Type: application/x-www-form-urlencodedrn";
$out .= "User-Agent: $_SERVER[HTTP_USER_AGENT]rn";
$out .= "ホスト: $hostrn";
$out .= 'Content-Length: '.strlen($post)."rn";
$out .= "接続: Closern";
$out .= "キャッシュ制御: no-cachern";
$out .= "Cookie: $cookiernrn";
$out .= $post;
} else {
$out = "GET $path HTTP/1.0rn";
$ out .= "Accept: */*rn";
$out .= "Accept-Language: zh-cnrn";
$out .= "ユーザーエージェント: $_SERVER[HTTP_USER_AGENT]rn";
$out .= "ホスト: $hostrn";
$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);
@fclose($fp);
}
}
例:
dfopen("http://sina.com",0);