{
$ip = gethostbyname($host);
//echo "ip=$ip<br>";
[email=$fp=@fsockopen($ip,80]$fp=@fsockopen($ip,80[/email]);
if (!$fp) return;
fputs($fp, "$methodrn");
fputs($fp, "Host: $hostrn");
if (!empty($sessid))
{
fputs($fp, ": PHPSESSID=$sessid; path=/;rn");
}
if ( substr(trim($method),0, 4) == "POST")
{
fputs($fp, "Content-Length: ". strlen($str) . "rn"); // 别忘了指定长度
}
//fputs($fp, "Content-Type: application/x-www-form-urlencodedrnrn");
fputs($fp, "Content-Type: application/x-www-form-urlencodedrn");
fputs($fp, "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1;
InfoPath.1)rn)");//add by Ew 071012
fputs($fp, "Connection: Keep-Alivernrn");
if ( substr(trim($method),0, 4) == "POST")
{
fputs($fp, $str."rn");
}
while(!feof($fp))
{
$response .= fgets($fp);
}
$hlen = strpos($response,"rnrn"); // LINUX 下是 "nn"
$header = substr($response, 0, $hlen);
//echo "header=$header<hr><hr>";
$entity = substr($response, $hlen + 4);
if ( preg_match('/PHPSESSID=([0-9a-z]+);/i', $header, $matches))
{
$a['sessid'] = $matches[1];
}
if ( preg_match('/Location: ([0-9a-z_?=&#.]+)/i', $header, $matches))
{
$a['location'] = $matches[1];
}
$a['content'] = $entity;
fclose($fp);
return $a;
}