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

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; //www.php.cn

}

$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中文网,转载请注明出处,感谢您的尊重!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值