多谢楼上的仁兄! 我要用file读取网页内容,fopen()不行吧!请您继续赐教!多谢!

解决方案 »

  1.   

    我刚才试验了一下,还是老毛病,用fopen()在本机上可以调用远程文件,但在虚拟服务器上又没有反映了,哭啊!
      

  2.   

    查看  php.ini 配置文件中   allow_url_fopen 选项是否打开
      

  3.   

    多谢您!cqq(脑电波) ,allow_url_fopen服务器上phpinfo显示on,我的机器上phpinfo显示on!都开启的!
      

  4.   

    不是吧,连这两个函数也禁用?那还叫PHP空间吗?
      

  5.   

    给出详细的错误信息另外在服务器上测试
    file('http://localhost/页面名.php');
      

  6.   

    多谢!
    thisky(···Cos.X···)
    keaizhong(可爱钟)(温州的PHPER)(19801010) 
    xuzuning(唠叨)他没有错误信息,就是没有反映了!一直等到超时!我测试一个简单的代码,如下:<?PHP
    //调用index2.php文件,显示aaaaaaaaaa 和 cccccccc中间的东西。
    $strSoHuGNXW = file("index2.php"); 
    $SoHucount = count($strSoHuGNXW);
    for ($i=0;$i<$SoHucount;$i++){
         $fileSoHuGNXW .= $strSoHuGNXW[$i];
     
    $SoHuGNGD = explode("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",$fileSoHuGNXW);
    $SoHuGNGD = explode("ccccccccccccccccccccccccccccccccc",$SoHuGNGD[1]);
    $SoHuGNGD = $SoHuGNGD[0];
    }
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>无标题文档</title>
    </head><?php echo $SoHuGNGD; ?><body>
    </body>
    </html>因为index2.php ,aaaa和cccc,中间是bbbbbb,就显示bbbbb了,可是传到服务器上就没有反映了,一直到超时!
      

  7.   

    我女朋友刚才帮我找一个代码:
    <?php
    $r=new HTTPRequest("http://my.haokan123.com/Diary/Html/HaoKan123_V2_44481.Html");
     $htm=$r->DownloadToString();
     echo $htm;
     
    class HTTPRequest
    {
    /*
    获取网页
    */
       var $_fp;        // HTTP socket
       var $_url;        // full URL
       var $_host;        // HTTP host
       var $_protocol;    // protocol (HTTP/HTTPS)
       var $_uri;        // request URI
       var $_port;        // port
       
       // scan url
       function _scan_url()
       {
           $req = $this->_url;
           
           $pos = strpos($req, '://');
           $this->_protocol = strtolower(substr($req, 0, $pos));
           
           $req = substr($req, $pos+3);
           $pos = strpos($req, '/');
           if($pos === false)
               $pos = strlen($req);
           $host = substr($req, 0, $pos);
           
           if(strpos($host, ':') !== false)
           {
               list($this->_host, $this->_port) = explode(':', $host);
           }
           else 
           {
               $this->_host = $host;
               $this->_port = ($this->_protocol == 'https') ? 443 : 80;
           }
           
           $this->_uri = substr($req, $pos);
           if($this->_uri == '')
               $this->_uri = '/';
       }
       
       // constructor
       function HTTPRequest($url)
       {
           $this->_url = $url;
           $this->_scan_url();
       }
       
       // download URL to string
       function DownloadToString()
       {
           $crlf = "\r\n";
           $response="";
           // generate request
           $req = 'GET ' . $this->_uri . ' HTTP/1.0' . $crlf
               .    'Host: ' . $this->_host . $crlf
               .    $crlf;
           
           // fetch
           $this->_fp = fsockopen(($this->_protocol == 'https' ? 'ssl://' : '') . $this->_host, $this->_port);
           fwrite($this->_fp, $req);
           while(is_resource($this->_fp) && $this->_fp && !feof($this->_fp))
               $response .= fread($this->_fp, 1024);
           fclose($this->_fp);
           
           // split header and body
           $pos = strpos($response, $crlf . $crlf);
           if($pos === false)
               return($response);
           $header = substr($response, 0, $pos);
           $body = substr($response, $pos + 2 * strlen($crlf));
           
           // parse headers
           $headers = array();
           $lines = explode($crlf, $header);
           foreach($lines as $line)
               if(($pos = strpos($line, ':')) !== false)
                   $headers[strtolower(trim(substr($line, 0, $pos)))] = trim(substr($line, $pos+1));
           
           // redirection?
           if(isset($headers['location']))
           {
               $http = new HTTPRequest($headers['location']);
               return($http->DownloadToString($http));
           }
           else 
           {
               return($body);
           }
       }
    }
    ?>这个代码在服务器上就可以调用外部文件了!!!! 到底为什么呢? 多谢热心的各位仁兄!!多谢!!!
      

  8.   

    回xuzuning(唠叨) 兄,file('http://localhost/页面名.php');直接超时!多谢您!
      

  9.   

    <pre>
    <?php
    echo ini_get("disable_functions");
    print_r(ini_get_all());
    ?>
    </pre>结果中搜索disable_functions
      

  10.   

    楼主
    2006-5-18 16:27:55
    发的测试程序如果运行有问题
    那就是file() disable了换用其他的函数
    file_get_contents() / fopen()
    fopen() eg:
       if(!$fh=fopen($url,"r")){
            die("could not open $url");
    }
       while(!feof($fh)){
         $line.=fgets($fh,4096);
       }
    fclose($fh);