php模仿用户访问网页程序代码
发布:smiling 来源: PHP粉丝网 添加日期:2014-08-17 20:29:34 浏览: 评论:0
- 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));
Tags: php模仿用户 网页程序代码
- 上一篇:php无限级创建目录几个函数
- 下一篇:获取url中部份内容代码
推荐文章
热门文章
最新评论文章
- 写给考虑创业的年轻程序员(10)
- PHP新手上路(一)(7)
- 惹恼程序员的十件事(5)
- PHP邮件发送例子,已测试成功(5)
- 致初学者:PHP比ASP优秀的七个理由(4)
- PHP会被淘汰吗?(4)
- PHP新手上路(四)(4)
- 如何去学习PHP?(2)
- 简单入门级php分页代码(2)
- php中邮箱email 电话等格式的验证(2)