摘要:functionhttpget($url,$followredirects=true){global$final_url;$url_parsed=parse_url($url);if(emptyempty($url_parsed['scheme&#39......
轉(zhuǎn)載請(qǐng)注明來源:php模仿用戶訪問網(wǎng)頁程序代碼
轉(zhuǎn)載請(qǐng)注明來源:php模仿用戶訪問網(wǎng)頁程序代碼
- function httpget( $url, $followredirects=true ) {
- global $final_url;
- $url_parsed = parse_url($url);
- if ( emptyempty($url_parsed['scheme']) ) {
- $url_parsed = parse_url('http://'.$url);
- }
- $final_url = $url_parsed;
- $port = $url_parsed["port"];
- if ( !$port ) {
- $port = 80; //開源代碼phpfensi.com
- }
- $rtn['url']['port'] = $port;
- $path = $url_parsed["path"];
- if ( emptyempty($path) ) {
- $path="/";
- }
- if ( !emptyempty($url_parsed["query"]) ) {
- $path .= "?".$url_parsed["query"];
- }
- $rtn['url']['path'] = $path;
- $host = $url_parsed["host"];
- $foundbody = false;
- $out = "get $path http/1.0 ";
- $out .= "host: $host ";
- $out .= "user-agent: mozilla/5.0 (windows; u; windows nt 5.1; en-us; rv:1.8.1) gecko/20061010 firefox/2.0 ";
- $out .= "connection: close ";
- if ( !$fp = @fsockopen($host, $port, $errno, $errstr, 30) ) {
- $rtn['errornumber'] = $errno;
- $rtn['errorstring'] = $errstr;
- }
- fwrite($fp, $out);
- while (!@feof($fp)) {
- $s = @fgets($fp, 128);
- if ( $s == " " ) {
- $foundbody = true;
- continue;
- }
- if ( $foundbody ) {
- $body .= $s;
- } else {
- if ( ($followredirects) && (stristr($s, "location:") != false) ) {
- $redirect = preg_replace("/location:/i", "", $s);
- return httpget( trim($redirect) );
- }
- $header .= $s;
- }
- }
- fclose($fp);
- return(trim($body));
哈爾濱品用軟件有限公司致力于為哈爾濱的中小企業(yè)制作大氣、美觀的優(yōu)秀網(wǎng)站,并且能夠搭建符合百度排名規(guī)范的網(wǎng)站基底,使您的網(wǎng)站無需額外費(fèi)用,即可穩(wěn)步提升排名至首頁。歡迎體驗(yàn)最佳的哈爾濱網(wǎng)站建設(shè)。
