function webcontent($host,$port,$res='/',$postdata=array(),$cookie=array(),$referer='') {
if (!is_array($cookie) { if (empty($referer) && !empty($cookie)) { $referer = $cookie; } $cookie = array(); }
$post = ''; if (is_array($postdata)) foreach ($postdata as $key => $value)
$post.='&'.rawurlencode($key).'='.rawurlencode($value);
$post = substr($post,1);
$cookietxt = ''; foreach ($cookie as $key => $value)
$cookietxt.=$key.'='.$value.'; ';
$cookietxt.='0';
$request = (sizeOf($postdata)?'POST':'GET')." ".$res." HTTP/1.1\r\n".
"Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, */*\r\n".
(strlen($referer)?'Referer: '.$referer."\r\n":'').
(sizeOf($postdata)?"Content-Type: application/x-www-form-urlencoded\r\n":'').
"Accept-Encoding: gzip, deflate\r\n".
((empty($cookietxt))?'':'Cookie: '.$cookietxt."\r\n").
"User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Win98; DigExt)\r\n".
"Host: ".$host.(($port==80)?'':':'.$port)."\r\n".
(sizeOf($postdata)?"Content-Length: ".strlen($post)."\r\n":'').
"Connection: close\r\n".
"Cache-control: no-cache\r\n\r\n".$post;
if (!$fp = fsockopen($host,$port,$err,$err,1.0)) return NULL;
fwrite($fp,$request); $buf = ''; while (!feof($fp)) $buf.=fread($fp,1024);
fclose($fp); $buf = explode("\r\n\r\n",$buf,2);
$buf[0] = explode("\r\n",$buf[0]); $header = array();
$status = array_shift($buf[0]);
for ($i=0; $i<sizeOf($buf[0]); $i++) {
$buf[0][$i] = explode(': ',$buf[0][$i],2);
$header[strtolower($buf[0][$i][0])] = $buf[0][$i][1];
}
if (isset($header['content-encoding'])) {
switch (strtolower($header['content-encoding'])) {
case 'deflate':
case 'gzip':
$buf[1] = gzinflate(substr($buf[1],10));
break;
}
}
if (isset($header['set-cookie'])) {
if (!is_array($cookie)) $cookie = array();
if (preg_match_all('/(\w+?)=([^\s;]*)/',$header['set-cookie'],$x))
for ($i=0;$i<sizeOf($x[0]);$i++) $cookie[$x[1][$i]]=$x[2][$i];
}
return array('status'=>$status,'header'=>$header,'cookie'=>$cookie,'content'=>$buf[1]);
}