[php]代码库
// $url = 'http://yuncode.net';
$url = 'http://yuncode.net:80/php/sock.php?site=yuncode.net';
function get_url($url,$cookie=false)
{
$url = parse_url($url);
$query = $url['path']."?".$url['query'];
echo "Query:".$query;
$fp = fsockopen( $url['host'], $url['port']?$url['port']:80 , $errno, $errstr, 30);
if (!$fp)
{
return false;
}
else {
$request = "GET $query HTTP/1.1\r\n";
$request .= "Host: $url[host]\r\n";
$request .= "Connection: Close\r\n";
if($cookie) $request.="Cookie: $cookie\n";
$request.="\r\n";
fwrite($fp,$request);
$result = '';
while(!feof($fp))
{
$result .= @fgets($fp, 1024);
}
fclose($fp);
return $result;
}
}
//获取url的html部分,去掉header
function GetUrlHTML($url,$cookie=false)
{
$rowdata = get_url($url,$cookie);
if($rowdata)
{
$body= stristr($rowdata,"\r\n\r\n");
$body=substr($body,4,strlen($body));
return $body;
}
return false;
}
echo get_url($url);
echo GetUrlHTML($url);