日期:2014-05-17 浏览次数:20471 次
function get_content_by_socket($url){
$url = eregi_replace('^http://', '', $url);
$temp = explode('/', $url);
$host = array_shift($temp);
$url = ''.implode('/', $temp);
$temp = explode(':', $host);
$host = $temp[0];
$port = isset($temp[1]) ? $temp[1] : 80;
//echo $url;
//echo $host;
$fp = fsockopen($host, 80) or die("Open ". $url ." failed");
$header = "GET /".$url ." HTTP/1.1\r\n";
$header .= "Accept: */*\r\n";
$header .= "Accept-Language: zh-cn\r\n";
$header .= "Accept-Encoding: gzip, deflate\r\n";
$header .= "If-Modified-Since: Tue, 06 Apr 2010 07:56:03 GMT; length=2235\r\n";
$header .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; GTB6.4)\r\n";
$header .= "Host: ". $host ."\r\n";
$header .= "Referer: http://video.baidu.com/v?word=11&ct=301989888&rn=20&pn=0&db=0&s=0&fbl=800\r\n";
//fputs($content, "Referer: $domainrn");//伪造部分
$header .= "Connection: Keep-Alive\r\n";
$header .= "Cookie: BAIDUID=5F96971273579588527A980F307E8B7A:FG=1\r\n\r\n";
//$header .= "Connection: Close\r\n\r\n";
fwrite($fp, $header);
while (!feof($fp)) {
$contents .= fgets($fp, 8192);
}
fclose($fp);
return $contents;
}