1
function get_page_content($url){
2
$url = eregi_replace('^http://', '', $url);
3
$temp = explode('/', $url);
4
$host = array_shift($temp);
5
$path = '/'.implode('/', $temp);
6
$temp = explode(':', $host);
7
$host = $temp[0];
8
$port = isset($temp[1]) ? $temp[1] : 80;
9
$fp = @fsockopen($host, $port, &$errno, &$errstr, 30);
10
if ($fp){
11
@fputs($fp, “GET $path HTTP/1.1\r\nHost: $host\r\nAccept: */*\r\nReferer:$url\r\nUser-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)\r\nConnection: Close\r\n\r\n”);
12
}
13
$Content = ”;
14
while ($str = @fread($fp, 4096)){
15
$Content .= $str;
16
}
17
@fclose($fp);
18
//重定向
19
if(preg_match(”/^HTTP\/\d.\d 301 Moved Permanently/is”,$Content)){
20
if(preg_match(”/Location:(.*?)\r\n/is”,$Content,$murl)){
21
return get_page_content($murl[1]);
22
}
23
}
24
//读取内容
25
if(preg_match(”/^HTTP\/\d.\d 200 OK/is”,$Content)){
26
preg_match(”/Content-Type:(.*?)\r\n/is”,$Content,$murl);
27
$contentType=trim($murl[1]);
28
$Content=explode(”\r\n\r\n”,$Content,2);
29
$Content=$Content[1];
30
}
31
return $Content;
32
}
33
34