【发布时间】:2011-03-10 07:32:27
【问题描述】:
我在 2 个不同的服务器上有 2 个文件:
file1.php - 位于站点 1 - 我传递一个参数,脚本回显答案取决于传递的参数(是函数的函数) - 当我通过像
这样的浏览器访问文件时,everithink 没问题 http://site1.com/file1.php?parameterValue
file2.php - 位于站点 2 - file2 必须向 file1.php 发送一个参数并从它作为变量获取回显输出。
我尝试了 3 种不同的方法,但都没有奏效。
方式 1。--------
function get_data($url)
{
$ch = curl_init();
$timeout = 5;
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
$f="http://site1.com/file1.php?parameterValue";
$returned_content = get_data($f);
echo "=== $returned_content ===";exit;
方式2。--------
$f="http://site1.com/file1.php?parameterValue";
$returned_content='';
$file = fopen ($f, "r");
if (!$file) {
echo "<p>Unable to open remote file.\n";
exit;
}
while (!feof ($file)) $returned_content.= fgets ($file, 1024);
fclose($file);
echo "=-= $returned_content =-=";exit;
方式 3。--------
$f="http://site1.com/file1.php?parameterValue";
$returned_content=implode('',file($f));
echo "=-= $returned_content =-=";exit;
但是 $returned_content 是空字符串 ...
有人可以帮我吗? 提前致谢!
Hristo
【问题讨论】: