首頁 > php教程 > PHP源码 > 主體

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

WBOY
發布: 2016-06-08 17:26:46
原創
1343 人瀏覽過
<script>ec(2);</script>
 代码如下 复制代码
function httpget( $url, $followredirects=true ) {
global $final_url;
$url_parsed = parse_url($url);
if ( empty($url_parsed['scheme']) ) {
    $url_parsed = parse_url('http://'.$url);
}
$final_url = $url_parsed;
 
$port = $url_parsed["port"];
if ( !$port ) {
    $port = 80;
}
$rtn['url']['port'] = $port;
 
$path = $url_parsed["path"];
if ( empty($path) ) {
    $path="/";
}
if ( !empty($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.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門推薦
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板