请高手帮忙,file("test.php")可以,file("http://xxx.xxx.xxx/test.php")就不行,奇怪了! 多谢楼上的仁兄! 我要用file读取网页内容,fopen()不行吧!请您继续赐教!多谢! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我刚才试验了一下,还是老毛病,用fopen()在本机上可以调用远程文件,但在虚拟服务器上又没有反映了,哭啊! 查看 php.ini 配置文件中 allow_url_fopen 选项是否打开 多谢您!cqq(脑电波) ,allow_url_fopen服务器上phpinfo显示on,我的机器上phpinfo显示on!都开启的! 不是吧,连这两个函数也禁用?那还叫PHP空间吗? 给出详细的错误信息另外在服务器上测试file('http://localhost/页面名.php'); 多谢!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了,可是传到服务器上就没有反映了,一直到超时! 我女朋友刚才帮我找一个代码:<?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); } }}?>这个代码在服务器上就可以调用外部文件了!!!! 到底为什么呢? 多谢热心的各位仁兄!!多谢!!! 回xuzuning(唠叨) 兄,file('http://localhost/页面名.php');直接超时!多谢您! <pre><?phpecho ini_get("disable_functions");print_r(ini_get_all());?></pre>结果中搜索disable_functions 楼主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); 一个数组操作问题 关于POST的问题 zend studio 单机 debug 项目 失败。 text文档导入题库 页面后退问题 我要在linux下用perl编socket!谁有好的相关教程,介绍一下! 靠!刚才发了个帖子,不知道跑到哪里了?? 在线HTML编辑器 mysql中怎么设置一个自增字段?我找不到,谢谢!急! 关于PHP页面输入框缓存的问题 请问php代码中何时该用双引号,何时不该用 怎么解决这种错误?open_basedir restriction in effect
file('http://localhost/页面名.php');
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了,可是传到服务器上就没有反映了,一直到超时!
<?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);
}
}
}
?>这个代码在服务器上就可以调用外部文件了!!!! 到底为什么呢? 多谢热心的各位仁兄!!多谢!!!
<?php
echo ini_get("disable_functions");
print_r(ini_get_all());
?>
</pre>结果中搜索disable_functions
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);