首页 > 后端开发 > php教程 > php模仿用户访问网页程序代码

php模仿用户访问网页程序代码

高洛峰
发布: 2016-11-29 15:55:02
原创
1320 人浏览过

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; //m.sbmmt.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));
登录后复制


相关标签:
php
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板